public void SaveEquityType(EquityType equityType) { using (DeepBlueEntities context = new DeepBlueEntities()) { if (equityType.EquityTypeID == 0) { context.EquityTypes.AddObject(equityType); } else { // Define an ObjectStateEntry and EntityKey for the current object. EntityKey key = default(EntityKey); object originalItem = null; key = context.CreateEntityKey("EquityTypes", equityType); // 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, equityType); } } context.SaveChanges(); } }
private IEnumerable<ErrorInfo> Validate(EquityType equityType) { return ValidationHelper.Validate(equityType); }
public ActionResult UpdateEquityType(FormCollection collection) { EditEquityTypeModel model=new EditEquityTypeModel(); ResultModel resultModel=new ResultModel(); this.TryUpdateModel(model); string ErrorMessage=EquityTypeNameAvailable(model.EquityType,model.EquityTypeId); if(String.IsNullOrEmpty(ErrorMessage)==false) { ModelState.AddModelError("Equity",ErrorMessage); } if(ModelState.IsValid) { EquityType equityType=AdminRepository.FindEquityType(model.EquityTypeId); if(equityType==null) { equityType=new EquityType(); equityType.CreatedBy=Authentication.CurrentUser.UserID; equityType.CreatedDate=DateTime.Now; } equityType.Equity=model.EquityType; equityType.Enabled=model.Enabled; equityType.EntityID=Authentication.CurrentEntity.EntityID; equityType.LastUpdatedBy=Authentication.CurrentUser.UserID; equityType.LastUpdatedDate=DateTime.Now; IEnumerable<ErrorInfo> errorInfo=AdminRepository.SaveEquityType(equityType); if(errorInfo!=null) { resultModel.Result+=ValidationHelper.GetErrorInfo(errorInfo); } else { resultModel.Result="True||"+equityType.EquityTypeID; } } 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); }