예제 #1
0
func (this *AdminController) DeleteIncident() {
	o := orm.NewOrm()
	o.Using("default")

	incidentId, _ := strconv.Atoi(this.Ctx.Input.Param(":id"))

	incidents := models.Incident{}

	flash := beego.NewFlash()

	if exist := o.QueryTable(incidents.TableName()).Filter("Id", incidentId).Exist(); exist {
		if num, err := o.Delete(&models.Incident{Id: incidentId}); err == nil {
			beego.Info("Record Deleted. ", num)
			flash.Notice("L'incident a bien été supprimé")
		} else {
			beego.Error("L'incident n'a pu être supprimé. Raison: ", err)
		}

	} else {
		flash.Notice("L'incident n'existe pas %d", incidentId)
	}

	flash.Store(&this.Controller)

	this.Redirect("/incident-manager/admin/", 302)
}
예제 #2
0
func (this *IndexController) Edit() {
	o := orm.NewOrm()
	o.Using("default")

	incidentId, _ := strconv.Atoi(this.Ctx.Input.Param(":id"))
	incidents := models.Incident{}

	flash := beego.NewFlash()

	err := o.QueryTable("incident").Filter("id", incidentId).One(&incidents)

	if err != orm.ErrNoRows {

		err := this.ParseForm(&incidents)
		if err != nil {

			beego.Error("Impossible de parser. Raison: ", err)

		} else {
			timer := time.NewTimer(time.Second * 60)
			stop := timer.Stop()
			if this.Ctx.Input.Method() == "POST" {
				confirmUser := this.Ctx.Input.Request.FormValue("confirmUser")
				if confirmUser == "2" || confirmUser == "3" {
					incidents.DateResolution = time.Time{}
				}
				num, err := o.Update(&incidents)
				if err == nil {
					if num > 0 {

						if confirmUser == "1" {

							flash.Warning("Incident : " + incidents.Title + " terminé. Merci à toi.")
							flash.Store(&this.Controller)

						} else if confirmUser == "2" || confirmUser == "3" {
							fmt.Println("Stop timer", stop)
							fmt.Println("mysql row affected nums: ", num)
							flash.Warning("Incident : " + incidents.Title + " de nouveau renvoyé à l'administrateur")
							flash.Store(&this.Controller)
						}

					} else {
						flash.Error("Rien a été modifié pour l'incident : " + incidents.Title)
						flash.Store(&this.Controller)
					}

					this.Redirect("/incident-manager/", 302)

				} else {
					fmt.Println("erreur")

					beego.Debug("Mise à jour Impossible dû a : ", err)
				}

			}

		}
		this.Redirect("/incident-manager/", 302)

	} else {
		flash.Error("Incident %d n'existe pas", incidentId)
		flash.Store(&this.Controller)
		this.Redirect("/incident-manager/", 302)
	}

}