public void SaveInvestorEntityType(InvestorEntityType investorEntityType) { using (DeepBlueEntities context = new DeepBlueEntities()) { if (investorEntityType.InvestorEntityTypeID == 0) { context.InvestorEntityTypes.AddObject(investorEntityType); } else { // Define an ObjectStateEntry and EntityKey for the current object. EntityKey key = default(EntityKey); object originalItem = null; key = context.CreateEntityKey("InvestorEntityTypes", investorEntityType); // 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, investorEntityType); } } context.SaveChanges(); } }
private IEnumerable<ErrorInfo> Validate(InvestorEntityType investorEntityType) { return ValidationHelper.Validate(investorEntityType); }
public ActionResult UpdateInvestorEntityType(FormCollection collection) { EditInvestorEntityTypeModel model=new EditInvestorEntityTypeModel(); ResultModel resultModel=new ResultModel(); this.TryUpdateModel(model); string ErrorMessage=InvestorEntityTypeNameAvailable(model.InvestorEntityTypeName,model.InvestorEntityTypeId); if(String.IsNullOrEmpty(ErrorMessage)==false) { ModelState.AddModelError("InvestorEntityTypeName",ErrorMessage); } if(ModelState.IsValid) { InvestorEntityType investorEntityType=AdminRepository.FindInvestorEntityType(model.InvestorEntityTypeId); if(investorEntityType==null) { investorEntityType=new InvestorEntityType(); } investorEntityType.InvestorEntityTypeName=model.InvestorEntityTypeName; investorEntityType.Enabled=model.Enabled; investorEntityType.EntityID=Authentication.CurrentEntity.EntityID; IEnumerable<ErrorInfo> errorInfo=AdminRepository.SaveInvestorEntityType(investorEntityType); if(errorInfo!=null) { resultModel.Result+=ValidationHelper.GetErrorInfo(errorInfo); } else { resultModel.Result="True||"+investorEntityType.InvestorEntityTypeID; } } 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); }