Example #1
0
 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;
 }
Example #2
0
 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;
     }
 }