public static UpdateAccount CreateUpdateAccount(Account account) { var updateAccount = new UpdateAccount(); updateAccount.ID = account.ID; updateAccount.LoginID = account.LoginID; updateAccount.Name = account.Name; updateAccount.State = account.State; return updateAccount; }
public ActionResult Edit(UpdateAccount updateAccount) { try { // TODO: Add update logic here var accountServices = ServiceLocator.Instance.GetService<IAccountServices>(); accountServices.Update(updateAccount); var result = accountServices.GetResult(); return Json(result); } catch { return View(); } }
// GET: Manage/Account/Create public ActionResult Create(Guid? id) { var accountServices = ServiceLocator.Instance.GetService<IAccountServices>(); var updateAccount = new UpdateAccount(); if (id.HasValue) { updateAccount = accountServices.GetAccount(id.Value); } ViewBag.UpdateAccount = new HtmlString(updateAccount.ToJson()); var departmentServices = ServiceLocator.Instance.GetService<IDepartmentServices>(); var departments = departmentServices.Get(); ViewBag.Departments = new HtmlString(departments.ToJson()); return PartialView(); }
public void Update(UpdateAccount updateAccount) { if (updateAccount.ID == Guid.Empty) { Add(updateAccount); } else { Edit(updateAccount); } }
public void Edit(UpdateAccount updateAccount) { using (var defaultContent = new DefaultContext()) { var account = defaultContent.Accounts.FirstOrDefault(x => x.ID == updateAccount.ID); if (account.Null()) { Message = "请选择要修改的账号"; return; } account.LastLoginTime = DateTime.Now; account.LoginID = updateAccount.LoginID; account.Name = updateAccount.Name; defaultContent.ModifiedModel(account); var workCards = defaultContent.WorkCards.Where(x => x.AccountId == updateAccount.ID).ToList(); if (workCards.Count() == 1) { var workCard = workCards.FirstOrDefault(); workCard.DepartmentId = updateAccount.DepartmentId; defaultContent.ModifiedModel(workCard); } if (!workCards.Any()) { var workCard = new WorkCard(); workCard.ID = Guid.NewGuid(); workCard.AccountId = updateAccount.ID; workCard.DepartmentId = updateAccount.DepartmentId; defaultContent.WorkCards.Add(workCard); } defaultContent.SaveChanges(); } Flag = true; }
public void Add(UpdateAccount updateAccount) { using (var defaultContent = new DefaultContext()) { var exit = defaultContent.Accounts.Any(x => x.LoginID == updateAccount.LoginID.Trim()); if (exit) { Flag = false; Message = "已经存在相同的账号"; return; } var account = updateAccount.CreateAccount(); defaultContent.Accounts.Add(account); if (updateAccount.DepartmentId != Guid.Empty) { var workCard = new WorkCard(); workCard.ID = Guid.NewGuid(); workCard.DepartmentId = updateAccount.DepartmentId; workCard.AccountId = account.ID; defaultContent.WorkCards.Add(workCard); } defaultContent.SaveChanges(); Flag = true; } }