public override void Setup() { base.Setup(); // Spin up mock repository and attach to controller MockService = new Mock<ICashDistributionTypeService>(); DefaultCashDistributionType = new DeepBlue.Models.Entity.CashDistributionType(MockService.Object); MockService.Setup(x => x.SaveCashDistributionType(It.IsAny<DeepBlue.Models.Entity.CashDistributionType>())); }
public ActionResult UpdateCashDistributionType(FormCollection collection) { EditCashDistributionTypeModel model=new EditCashDistributionTypeModel(); ResultModel resultModel=new ResultModel(); this.TryUpdateModel(model); string ErrorMessage=CashDistributionTypeAvailable(model.Name,model.CashDistributionTypeId); if(String.IsNullOrEmpty(ErrorMessage)==false) { ModelState.AddModelError("Name",ErrorMessage); } if(ModelState.IsValid) { CashDistributionType cashDistributionType=AdminRepository.FindCashDistributionType(model.CashDistributionTypeId); if(cashDistributionType==null) { cashDistributionType=new CashDistributionType(); } cashDistributionType.Name=model.Name; cashDistributionType.Enabled=model.Enabled; cashDistributionType.EntityID=Authentication.CurrentEntity.EntityID; IEnumerable<ErrorInfo> errorInfo=AdminRepository.SaveCashDistributionType(cashDistributionType); if(errorInfo!=null) { resultModel.Result+=ValidationHelper.GetErrorInfo(errorInfo); } else { resultModel.Result="True||"+cashDistributionType.CashDistributionTypeID; } } else { foreach(var values in ModelState.Values.ToList()) { foreach(var err in values.Errors.ToList()) { if(string.IsNullOrEmpty(err.ErrorMessage)==false) { resultModel.Result+=err.ErrorMessage+"\n"; } } } } return View("Result",resultModel); }
private IEnumerable<ErrorInfo> Validate(CashDistributionType cashDistributionType) { return ValidationHelper.Validate(cashDistributionType); }