public ExpenseGroupViewModel GetAllExpenseGroups() { var mod = new ExpenseGroupViewModel(); mod.IsValid = true; try { mod.ExpenseGroups = _bdmSvc.GetAllExpenseGroups(AppConstants.SITE_CODE); } catch (Exception ex) { mod.IsValid = false; mod.Message = ex.Message; } return mod; }
public ExpenseGroupViewModel ModifyExpenseGroup(ExpenseGroupDE mod) { ExpenseGroupViewModel model = new ExpenseGroupViewModel(); try { DBOperations op = mod.IsActive ? DBOperations.Update : DBOperations.Delete; mod.SiteCode = AppConstants.SITE_CODE; _bdmSvc.ModifyExpenseGroup(mod); model.ExpenseGroup = new ExpenseGroupDE(); model.FieldId = "groupCode"; model.ExpenseGroups = _bdmSvc.GetAllExpenseGroups(AppConstants.SITE_CODE); //.GetAllExpenseGroups().Map(model.ExpenseGroups); model.Message = op == DBOperations.Update ? string.Format(AppConstants.CRUD_UPDATE, "ExpenseGroup") : string.Format(AppConstants.CRUD_DELETE, "ExpenseGroup"); } catch (Exception ex) { model.IsValid = false; model.Message = ex.Message; if (ex.Message.Contains("Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. See http://go.microsoft.com/fwlink/?LinkId=472540 for information on understanding and handling optimistic concurrency exceptions.")) { model.FieldId = "groupCode"; model.Message = "Unable to modify ExpenseGroup Code"; } } return model; }
public ExpenseGroupViewModel AddExpenseGroup(ExpenseGroupViewModel model) { try { model.IsValid = model.Validate(); if (model.IsValid) { if (_bdmSvc.ExpenseGroupCodeExists(AppConstants.SITE_CODE, model.ExpenseGroup.GroupCode)) { model.FieldId = "groupCode"; model.Message = string.Format(AppConstants.VALIDATION_ALREADY_EXISTS, "Group Code"); model.IsValid = false; } if (model.IsValid) { model.ExpenseGroup.SiteCode = AppConstants.SITE_CODE; _bdmSvc.AddExpenseGroup(model.ExpenseGroup); model.FieldId = "groupCode"; model.ExpenseGroup = new ExpenseGroupDE(); model.ExpenseGroups = _bdmSvc.GetAllExpenseGroups(AppConstants.SITE_CODE); model.Message = string.Format(AppConstants.CRUD_CREATE, "Expense Group"); } } } catch (Exception ex) { model.IsValid = false; model.Message = ex.Message; } return model; }