public IActionResult Edit(BranchEditViewModel model) { if (ModelState.IsValid) { Branch branch = _branchRepository.GetBranch(model.Id); branch.Name = model.Name; branch.City = model.City; branch.Address = model.Address; branch.PhoneNumber = model.PhoneNumber; if (model.Photo != null) { if (model.ExistingPhotoPath != null) { string filePath = Path.Combine(hostingEnvironment.WebRootPath, "images", model.ExistingPhotoPath); System.IO.File.Delete(filePath); } branch.PhotoPath = ProcessUploadedFile(model); } branch.BranchStatus = model.BranchStatus; _branchRepository.Update(branch); return(RedirectToAction("index", "home")); } return(View()); }
public ActionResult Edit(BranchEditViewModel vm) { if (ModelState.IsValid) { try { if (vm.Id > 0) { _branchService.UpdateBranch(vm); SystemMessages.Add(BranchStrings.Branch_Update_Success_Msg, false, true); } else { _branchService.SaveBranch(vm); SystemMessages.Add(BranchStrings.Branch_Add_Success_Msg, false, true); } return(RedirectToAction("Index")); } catch (Exception ex) { SystemMessages.Add(CommonStrings.Server_Error, true, true); } } return(View(vm)); }
public ActionResult Edit([Bind(Include = "Id,Address,Phone,Email,StartWork,EndWork")] BranchEditViewModel branchEditViewModel) { if (ModelState.IsValid) { var branch = _mapper.Map <Branch>(branchEditViewModel); branch.Company = _repositoryCompany.Get(branchEditViewModel.CompanyId); _repositoryBranch.Update(branch); return(RedirectToAction("Index")); } return(View(branchEditViewModel)); }
public ActionResult MapBranch(ComponentBranchMappingViewModel vm) { if (ModelState.IsValid) { try { if (_componentService.GetComponentList(filter: x => x.IsActive).Count == 0) { SystemMessages.Add(CommonStrings.No_Record, true, true); return(RedirectToAction("MapBranch")); } BranchEditViewModel branchVM = _branchService.GetBranchById(vm.BranchId); if (branchVM == null || !branchVM.IsActive || branchVM.IsHeadOffice) { SystemMessages.Add(ComponentStrings.Component_Map_Branch_Validation_InvalidBranch, true, true); return(RedirectToAction("MapBranch"));; } foreach (var i in vm.MappedComponentList) { if (!_componentService.GetComponentById(i.ComponentId).IsActive) { SystemMessages.Add(String.Format(ComponentStrings.Component_Map_Branch_Validation_InvalidComponent, i.ComponentName), true, true); return(RedirectToAction("MapBranch")); } } if (!_branchService.MapComponent(vm)) { SystemMessages.Add(CommonStrings.Server_Error, true, true); return(RedirectToAction("MapBranch")); } else { SystemMessages.Add(ComponentStrings.Component_Branch_Map_Successfull_Msg, false, true); return(RedirectToAction("MapBranch")); } } catch (Exception ex) { SystemMessages.Add(CommonStrings.Server_Error, true, true); return(RedirectToAction("MapBranch")); } } ViewBag.Title = ComponentStrings.Component_Map_Branch_Setup_Title; ViewBag.BranchDropDown = new SelectList(_branchService.GetBranchDropDown(x => x.IsActive && !x.IsHeadOffice), "Value", "Text"); return(View("MapBranch")); }
public void SaveBranch(BranchEditViewModel vm) { Branch branch = new Branch { Name = vm.Name, OpenDate = vm.OpenDate, IsHeadOffice = vm.IsHeadOffice, IsActive = vm.IsActive }; _uow.BranchRepository.Insert(branch); _uow.Save(); }
public void UpdateBranch(BranchEditViewModel vm) { Branch branch = new Branch { Id = vm.Id, Name = vm.Name, OpenDate = vm.OpenDate, IsHeadOffice = vm.IsHeadOffice, IsActive = vm.IsActive }; _uow.BranchRepository.Update(branch); _uow.Save(); }
public ViewResult Edit(int id) { Branch branch = _branchRepository.GetBranch(id); BranchEditViewModel branchEditViewModel = new BranchEditViewModel { Id = branch.Id, Name = branch.Name, City = branch.City, Address = branch.Address, PhoneNumber = branch.PhoneNumber, ExistingPhotoPath = branch.PhotoPath, BranchStatus = branch.BranchStatus }; return(View(branchEditViewModel)); }
public ActionResult Edit(BranchEditViewModel branchEditViewModel) { if (ModelState.IsValid) { Branch branch = new Branch() { Address = branchEditViewModel.Address, Email = branchEditViewModel.Email, EndWork = branchEditViewModel.EndWork, StepWork = branchEditViewModel.StepWork, Phone = branchEditViewModel.Phone, StartWork = branchEditViewModel.StartWork, Id = branchEditViewModel.Id }; _repository.Update(branch); return(RedirectToAction("Index")); } return(View(branchEditViewModel)); }
public ActionResult Edit(int id) { var branch = _repository.GetEntity(id); if (branch == null) { return(HttpNotFound()); } BranchEditViewModel branchEditViewModel = new BranchEditViewModel() { Address = branch.Address, Email = branch.Email, EndWork = branch.EndWork, Id = branch.Id, Phone = branch.Phone, StartWork = branch.StartWork, StepWork = branch.StepWork }; return(View(branchEditViewModel)); }
public ActionResult Edit(int?id) { if (!id.HasValue) { ViewBag.Title = "Create Branch"; return(View(new BranchEditViewModel() { OpenDate = DateTime.Now, IsActive = true })); } BranchEditViewModel vm = _branchService.GetBranchById(id.Value); if (vm != null) { ViewBag.Title = "Edit Branch"; return(View(vm)); } else { SystemMessages.Add(CommonStrings.No_Record, true, true); return(RedirectToAction("Index")); } }