public static Observation ToEntity(this ObservationsModel model, Observation source = null) { if (source == null) { source = new Observation { Id = source.Id, Name = source.Name, Noti_Alarm = source.Noti_Alarm, Code = source.Code, CreateDay = source.CreateDay, UpdateDay = source.UpdateDay, Low_Value = source.Low_Value, Hight_Value = source.Code, IsBieuDo = source.IsBieuDo }; } source.Id = model.Id; source.Name = model.Name; source.Noti_Alarm = model.Noti_Alarm; source.Code = model.Code; source.CreateDay = model.CreateDay; source.UpdateDay = model.UpdateDay; source.Low_Value = model.Low_Value; source.Hight_Value = model.Code; source.IsBieuDo = model.IsBieuDo; return(source); }
public IActionResult AddSecond(ObservationsModel model) { if (ModelState.IsValid) { var JsonStr = System.IO.File.ReadAllText("birds.json"); var JsonObj = JsonConvert.DeserializeObject <List <ObservationsModel> >(JsonStr); JsonObj.Add(model); System.IO.File.WriteAllText("birds.json", JsonConvert.SerializeObject(JsonObj, Formatting.Indented)); ViewBag.form = "Du har lagt till en observation!"; ModelState.Clear(); } return(View()); }
public ActionResult Create(ObservationsModel model) { if (ModelState.IsValid) { Observation pts = new Observation(); bool checkSave = false; pts.CreateDay = DateTime.Now; int CurrentUserId = WebMatrix.WebData.WebSecurity.CurrentUserId; pts = model.ToEntity(pts); checkSave = observationService.observationResponsitory.Insert(pts); TempData["MessageStatus"] = checkSave; TempData["Message"] = $"Thêm mới khu vực {(checkSave ? "" : "không")} thành công"; return(RedirectToAction("AreasManagement")); } return(View(model)); }
public ActionResult Create() { CMSHelper help = new CMSHelper(); @ViewBag.Title = ""; @ViewBag.MessageStatus = TempData["MessageStatus"]; @ViewBag.Message = TempData["Message"]; ObservationsModel model = new ObservationsModel(); List <Observation> groups = new List <Observation>(); int CurrentUserId = WebMatrix.WebData.WebSecurity.CurrentUserId; string userName = User.Identity.Name; groups = observationService.observationResponsitory.GetAll().ToList(); ViewBag.listGroup = groups; return(View(model)); }
public ActionResult Update(ObservationsModel model) { if (ModelState.IsValid) { Observation pts = observationService.observationResponsitory.Single(model.Id); if (pts == null) { return(RedirectToAction("ElementManagement")); } bool checkSave = false; pts = model.ToEntity(pts); checkSave = observationService.observationResponsitory.Update(pts); TempData["MessageStatus"] = checkSave; TempData["Message"] = $"Cập nhật trạm {(checkSave ? "" : "không")} thành công"; return(RedirectToAction("ElementManagement")); } return(View(model)); }
public ActionResult Update(int id = 0) { CMSHelper help = new CMSHelper(); @ViewBag.Title = ""; @ViewBag.MessageStatus = TempData["MessageStatus"]; @ViewBag.Message = TempData["Message"]; Observation pts = observationService.observationResponsitory.Single(id); if (pts == null) { return(RedirectToAction("ElementManagement")); } ObservationsModel model = pts.ToModel(); return(View(model)); }