public ActionResult Setup(int?id) { ComponentSetupViewModel vm = null; if (!id.HasValue) { ViewBag.Title = ComponentStrings.Component_Create_Title; vm = new ComponentSetupViewModel() { IsActive = true }; } else { ViewBag.Title = ComponentStrings.Component_Edit_Title; vm = _componentService.GetComponentById(id.Value); } if (vm == null) { SystemMessages.Add(CommonStrings.No_Record, true, true); return(RedirectToAction("Index")); } ViewBag.ComponentTypeDropDown = new SelectList(_componentTypeService.GetComponentTypeDropDown(), "Value", "Text"); ViewBag.DonorDropDown = new SelectList(_donorService.GetDonorDropDown(), "Value", "Text"); return(View("Setup", vm)); }
public void CreateComponent(ComponentSetupViewModel vm) { Component model = new Component { ComponentCode = vm.ComponentCode, Name = vm.Name, Duration = vm.Duration, ComponentTypeId = vm.ComponentTypeId, DonorId = vm.DonorId, IsActive = vm.IsActive, UserId = _userHelper.Get().UserId, SystemDate = _userHelper.Get().DayOpenClose.SystemDate, SetDate = DateTime.Now }; _uow.ComponentRepository.Insert(model); _uow.Save(); }
public ActionResult Setup(ComponentSetupViewModel vm) { if (ModelState.IsValid) { try { if (vm.Id > 0) { ViewBag.Title = ComponentStrings.Component_Edit_Title; if (_componentService.UpdateComponent(vm)) { SystemMessages.Add(ComponentStrings.Component_Update_Success_Msg, false, true); } else { SystemMessages.Add(CommonStrings.No_Record, true, true); } } else { ViewBag.Title = ComponentStrings.Component_Create_Title; _componentService.CreateComponent(vm); SystemMessages.Add(ComponentStrings.Component_Create_Success_Msg, false, true); } return(RedirectToAction("Index")); } catch (Exception ex) { SystemMessages.Add(CommonStrings.Server_Error, true, true); } } ViewBag.ComponentTypeDropDown = new SelectList(_componentTypeService.GetComponentTypeDropDown(), "Value", "Text", vm.ComponentTypeId); ViewBag.DonorDropDown = new SelectList(_donorService.GetDonorDropDown(), "Value", "Text", vm.DonorId); return(View("Setup", vm)); }
public bool UpdateComponent(ComponentSetupViewModel vm) { Component model = GetComponent(vm.Id); if (model == null) { return(false); } model.ComponentCode = vm.ComponentCode; model.Name = vm.Name; model.Duration = vm.Duration; model.ComponentTypeId = vm.ComponentTypeId; model.DonorId = vm.DonorId; model.IsActive = vm.IsActive; model.UserId = _userHelper.Get().UserId; model.SystemDate = _userHelper.Get().DayOpenClose.SystemDate; model.SetDate = DateTime.Now; _uow.ComponentRepository.Update(model); _uow.Save(); return(true); }