コード例 #1
0
 /// <summary>
 /// получение партнера со списком аккаунтов, для передачи его в форму добавления/редактирования
 /// </summary>
 /// <param name="Id">Id партнера для редактирования</param>
 /// <returns></returns>
 public PartnerViewModelForAddEditView GetPartnerWithMenegers(int? Id)
 {
     PartnerViewModelForAddEditView partnerView = new PartnerViewModelForAddEditView();
     if (Id == null)
     {
         //для возможности не выбирать менеджера
         User noManager = new User { Id = 0, Login = "******", Status = 1, CreatedDate = DateTime.Now, UpdatedDate = DateTime.Now };
         var listUser = accountRepository.Get().ToList<User>();
         listUser.Add(noManager);
         partnerView.Managers = new SelectList(listUser, "Id", "Login", 0);
     }
     else
     {
         var partner = partnerRepository.Get(Id.Value);
         if (partner != null)
         {
             partnerView = ConvertFromPartnerToPartnerViewModelForAddEditView(partner);
             if (partner.User == null)
             {
                 User noManager = new User { Id = 0, Login = "******", Status = 1, CreatedDate = DateTime.Now, UpdatedDate = DateTime.Now };
                 var listUser = accountRepository.Get().ToList<User>();
                 listUser.Add(noManager);
                 partnerView.Managers = new SelectList(listUser, "Id", "Login", 0);
             }
             else
                 partnerView.Managers = new SelectList(accountRepository.Get(), "Id", "Login", partner.UserId);
         }
     }
     return partnerView;
 }
コード例 #2
0
 public ActionResult Edit(PartnerViewModelForAddEditView partner)
 {
     try
     {
         if (ModelState.IsValid)
         {
             partnerService.Edit(partner);
             partnerService.SaveChanges();
             return RedirectToAction("Index");
         }
     }
     catch (Exception e)
     {
         ModelState.AddModelError("", "Unable to save changes");
     }
     return View(partner);
 }