public string InsertUpdateOtherExpense(OtherExpenseViewModel otherExpenseViewModel) { if (ModelState.IsValid) { try { //removiing combined code int len = otherExpenseViewModel.AccountCode.IndexOf(':'); otherExpenseViewModel.AccountCode = otherExpenseViewModel.AccountCode.Remove(len); // AppUA appUA = Session["AppUA"] as AppUA; otherExpenseViewModel.commonObj = new CommonViewModel(); SPAccounts.DataAccessObject.DTO.Common common = new SPAccounts.DataAccessObject.DTO.Common(); otherExpenseViewModel.commonObj.CreatedBy = appUA.UserName; otherExpenseViewModel.commonObj.CreatedDate = common.GetCurrentDateTime(); otherExpenseViewModel.commonObj.UpdatedBy = appUA.UserName; otherExpenseViewModel.commonObj.UpdatedDate = common.GetCurrentDateTime(); OtherExpenseViewModel otherExpenseVM = null; switch (otherExpenseViewModel.ID == Guid.Empty) { //INSERT case true: otherExpenseVM = Mapper.Map <OtherExpense, OtherExpenseViewModel>(_otherExpenseBusiness.InsertOtherExpense(Mapper.Map <OtherExpenseViewModel, OtherExpense>(otherExpenseViewModel))); return(JsonConvert.SerializeObject(new { Result = "OK", Record = otherExpenseVM })); default: //Getting UA otherExpenseVM = Mapper.Map <OtherExpense, OtherExpenseViewModel>(_otherExpenseBusiness.UpdateOtherExpense(Mapper.Map <OtherExpenseViewModel, OtherExpense>(otherExpenseViewModel))); return(JsonConvert.SerializeObject(new { Result = "OK", Record = otherExpenseVM })); } } catch (Exception ex) { return(JsonConvert.SerializeObject(new { Result = "ERROR", Message = ex.Message })); } } //Model state errror else { List <string> modelErrors = new List <string>(); foreach (var modelState in ModelState.Values) { foreach (var modelError in modelState.Errors) { modelErrors.Add(modelError.ErrorMessage); } } return(JsonConvert.SerializeObject(new { Result = "VALIDATION", Message = string.Join(",", modelErrors) })); } }