public void SaveFundExpenseType(FundExpenseType fundExpenseType)
 {
     using (DeepBlueEntities context = new DeepBlueEntities()) {
         if (fundExpenseType.FundExpenseTypeID == 0) {
             context.FundExpenseTypes.AddObject(fundExpenseType);
         }
         else {
             // Define an ObjectStateEntry and EntityKey for the current object.
             EntityKey key = default(EntityKey);
             object originalItem = null;
             key = context.CreateEntityKey("FundExpenseTypes", fundExpenseType);
             // 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, fundExpenseType);
             }
         }
         context.SaveChanges();
     }
 }
Exemple #2
0
 public ActionResult UpdateFundExpenseType(FormCollection collection)
 {
     EditFundExpenseTypeModel model=new EditFundExpenseTypeModel();
     ResultModel resultModel=new ResultModel();
     this.TryUpdateModel(model);
     string ErrorMessage=FundExpenseTypeAvailable(model.Name,model.FundExpenseTypeId);
     if(String.IsNullOrEmpty(ErrorMessage)==false) {
         ModelState.AddModelError("Name",ErrorMessage);
     }
     if(ModelState.IsValid) {
         FundExpenseType fundExpenseType=AdminRepository.FindFundExpenseType(model.FundExpenseTypeId);
         if(fundExpenseType==null) {
             fundExpenseType=new FundExpenseType();
         }
         fundExpenseType.Name=model.Name;
         fundExpenseType.EntityID=Authentication.CurrentEntity.EntityID;
         IEnumerable<ErrorInfo> errorInfo=AdminRepository.SaveFundExpenseType(fundExpenseType);
         if(errorInfo!=null) {
             resultModel.Result+=ValidationHelper.GetErrorInfo(errorInfo);
         } else {
             resultModel.Result="True||"+fundExpenseType.FundExpenseTypeID;
         }
     } 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);
 }