public ActionResult DevEdit(DevEditViewModel model) { if (!ViewBag.IsAdmin) { return RedirectToAction("Index", "Home"); } var dev = model.Id == -1 ? new T_Devs() : DbContext.T_Devs.First(item => item.Id == model.Id); dev.DevCode = model.DevCode; dev.StartTime = model.StartTime; dev.PreEndTime = model.PreEndTime; dev.EndTime = model.EndTime; dev.VideoURL = model.VideoUrl; dev.StatId = model.StatId.ToString(); dev.DevStatus = model.DevStatus; if (model.Id == -1) { DbContext.T_Devs.Add(dev); DbContext.SaveChanges(); var addr = new T_DevAddr { DevId = DbContext.T_Devs.First(obj => obj.DevCode == model.DevCode).Id, NodeId = Global.StringToHexByte(model.Addr) }; DbContext.T_DevAddr.Add(addr); } else { DbContext.T_Devs.Add(dev); } DbContext.SaveChanges(); return RedirectToAction("DevManage", "Admin"); }
public ActionResult DevEdit(string id) { if (!ViewBag.IsAdmin) { return RedirectToAction("Index", "Home"); } WdContext.SiteMapMenu.ActionMenu.Name = "编辑监测点"; var model = new DevEditViewModel(); if (string.IsNullOrWhiteSpace(id)) { WdContext.SiteMapMenu.ActionMenu.Name = "新增监测点"; model.Id = -1; model.IsNew = true; model.StartTime = DateTime.Now; model.PreEndTime = DateTime.Now; model.EndTime = DateTime.Now; } else { var dev = DbContext.T_Devs.First(item => item.Id.ToString() == id); model.Id = dev.Id; model.DevCode = dev.DevCode; model.StartTime = dev.StartTime; model.PreEndTime = dev.PreEndTime; model.EndTime = dev.EndTime; model.DevStatus = dev.DevStatus; model.StatId = int.Parse(dev.StatId); model.VideoUrl = dev.VideoURL; var devAddr = DbContext.T_DevAddr.First(obj => obj.DevId == dev.Id).NodeId; model.Addr = BitConverter.ToString(devAddr).Replace("-", string.Empty); } ViewBag.ReturnUrl = "/Admin/DevManage"; model.StatList = new SelectList(DbContext.T_Stats, "Id", "StatName", model.StatId); var statusList = new List<SelectListItem> { new SelectListItem() { Text = "是", Value = "1" }, new SelectListItem() { Text = "否", Value = "0" } }; model.StatusLIst = new SelectList(statusList, "Value", "Text", model.DevStatus); return View(model); }