Esempio n. 1
0
 public ActionResult Edit(ProductForAddEditViewModel productView, HttpPostedFileBase file = null)
 {
     try
     {
         if (ModelState.IsValid)
         {
             if (file != null)
             {
                 productView.Image = new byte[file.ContentLength];
                 file.InputStream.Read(productView.Image, 0, file.ContentLength);
             }
             productService.Edit(productView);
             productService.SaveChanges();
             return RedirectToAction("Index");
         }
     }
     catch
     {
         ModelState.AddModelError("", "Unable to save changes");
     }
     return View(productView);
 }
Esempio n. 2
0
 /// <summary>
 /// получение курса со списком аккаунтов и партнеров, для передачи его в форму добавления/редактирования
 /// </summary>
 /// <param name="Id">Id продукта для редактирования</param>
 /// <returns></returns>
 public ProductForAddEditViewModel GetProductWithAccauntsAndPartners(int? Id)
 {
     ProductForAddEditViewModel productView = new ProductForAddEditViewModel();
     if (Id == null)
     {
         //для возможности не выбирать менеджера
         User noManager = new User { Id = 0, Login = "******", Status = 1, CreatedDate = DateTime.Now, UpdatedDate = DateTime.Now };
         var listUser = accountRepository.Get().Where(m => m.Role.Equals("Manager")).ToList<User>();
         listUser.Add(noManager);
         productView.Accounts = new SelectList(listUser, "Id", "Login", 0);
         productView.Partners = new SelectList(partnerRepository.Get(), "PartnerId", "Name");
     }
     else
     {
         var product = productRepository.Get(Id.Value);
         if (product != null)
         {
             productView = ConvertFromProductToProductViewModelForAddEditView(product);
             User noManager = new User { Id = 0, Login = "******", Status = 1, CreatedDate = DateTime.Now, UpdatedDate = DateTime.Now };
             var listUser = accountRepository.Get().Where(m => m.Role.Equals("Manager")).ToList<User>();
             listUser.Add(noManager);
             productView.Accounts = new SelectList(listUser, "Id", "Login", 0);
             productView.Partners = new SelectList(partnerRepository.Get(), "PartnerId", "Name", product.PartnerId);
         }
     }
     return productView;
 }