Exemplo n.º 1
0
        public override void Setup()
        {
            base.Setup();

            // Spin up mock repository and attach to controller
            MockService = new Mock<IInvestorTypeService>();

            DefaultInvestorType = new DeepBlue.Models.Entity.InvestorType(MockService.Object);
            MockService.Setup(x => x.SaveInvestorType(It.IsAny<DeepBlue.Models.Entity.InvestorType>()));
        }
Exemplo n.º 2
0
 public void SaveInvestorType(InvestorType investorType)
 {
     using (DeepBlueEntities context = new DeepBlueEntities()) {
         if (investorType.InvestorTypeID == 0) {
             context.InvestorTypes.AddObject(investorType);
         } else {
             // Define an ObjectStateEntry and EntityKey for the current object.
             EntityKey key = default(EntityKey);
             object originalItem = null;
             key = context.CreateEntityKey("InvestorTypes", investorType);
             // Get the original item based on the entity key from the context
             // or from the database.
             if (context.TryGetObjectByKey(key, out originalItem)) {
                 // Call the ApplyCurrentValues method to apply changes
                 // from the updated item to the original version.
                 context.ApplyCurrentValues(key.EntitySetName, investorType);
             }
         }
         context.SaveChanges();
     }
 }
Exemplo n.º 3
0
 private IEnumerable<ErrorInfo> Validate(InvestorType investorType)
 {
     return ValidationHelper.Validate(investorType);
 }
Exemplo n.º 4
0
 public ActionResult UpdateInvestorType(FormCollection collection)
 {
     EditInvestorTypeModel model=new EditInvestorTypeModel();
     ResultModel resultModel=new ResultModel();
     this.TryUpdateModel(model);
     string ErrorMessage=InvestorTypeNameAvailable(model.InvestorTypeName,model.InvestorTypeId);
     if(String.IsNullOrEmpty(ErrorMessage)==false) {
         ModelState.AddModelError("InvestorTypeName",ErrorMessage);
     }
     if(ModelState.IsValid) {
         InvestorType investorType=AdminRepository.FindInvestorType(model.InvestorTypeId);
         if(investorType==null) {
             investorType=new InvestorType();
         }
         investorType.InvestorTypeName=model.InvestorTypeName;
         investorType.Enabled=model.Enabled;
         investorType.EntityID=Authentication.CurrentEntity.EntityID;
         IEnumerable<ErrorInfo> errorInfo=AdminRepository.SaveInvestorType(investorType);
         if(errorInfo!=null) {
             resultModel.Result+=ValidationHelper.GetErrorInfo(errorInfo);
         } else {
             resultModel.Result="True||"+investorType.InvestorTypeID;
         }
     } 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);
 }