public bool UpdateAccountType(tbl_Account_Types row) { try { using (var db = new SoneriCISEntities()) { tbl_Account_Types val = new DAL.tbl_Account_Types(); val = db.tbl_Account_Types.Where(a => a.ID == row.ID).FirstOrDefault(); if (db.tbl_Account_Types.Where(e => e.Name.ToLower() != val.Name.ToLower() && e.Name.ToLower() == row.Name.ToLower()).Any()) { throw new CustomException("Account type name already exists!"); } val.Name = row.Name; val.Code = row.Code; val.AuthorizationComments = row.AuthorizationComments; val.AuthorizationStatus = row.AuthorizationStatus; val.Description = row.Description; val.IsActive = row.IsActive; db.SaveChanges(); } return(true); } catch (Exception ex) { return(false); } }
public ActionResult AddUpdateAccountType(tbl_Account_Types request, int?RequestId = null) { if (IsDuplicateCode(request.ID, request.Code)) { return(Json(new { IsSuccess = false, ErrorMessage = CustomMessages.DuplicateAccountCode }, JsonRequestBehavior.AllowGet)); } //existing account type modification requests to be handled through System Request Section if (RequestId.HasValue /*request.ID != 0*/) { var getSystemRequest = new SystemRequestDataAccess().GetSystemRequest(RequestId.GetValueOrDefault(), "R"); var AccountTypeDetails = new AccountTypeDataAccess().GetAccountTypeDetailsById(request.ID); var existingJson = AccountTypeDetails == null ? null : CustomHelper.GetJson(AccountTypeDetails); var updatedJson = CustomHelper.GetJson(request); tbl_System_Requests row = new tbl_System_Requests(); if (RequestId.GetValueOrDefault() <= 0) { row = new tbl_System_Requests { AuthorizationStatus = "P", CreatorID = StateHelper.UserId, IsActive = true, ExistingData = existingJson, UpdatedData = updatedJson, RequestType = Constants.RequestTypes.AccountTypes_SystemRequest }; } else { row = getSystemRequest; row.CreatorID = StateHelper.UserId; row.AuthorizationStatus = "P"; row.AuthorizationComments = string.Empty; row.UpdatedData = updatedJson; row.ExistingData = existingJson; } var SystemRequestFlag = (RequestId.HasValue && RequestId.GetValueOrDefault() <= 0) ? new SystemRequestDataAccess().AddSystemRequest(row) : new SystemRequestDataAccess().UpdateSystemRequest(row); return(Json(new { IsSuccess = SystemRequestFlag, ErrorMessage = SystemRequestFlag == true ? string.Empty : CustomMessages.GenericErrorMessage, Response = SystemRequestFlag }, JsonRequestBehavior.AllowGet)); } else { request.IsActive = true; //New Account Type var response = request.ID <= 0 ? new AccountTypeDataAccess().AddAccountType(request) : new AccountTypeDataAccess().UpdateAccountType(request); return(Json(new { IsSuccess = response, ErrorMessage = response == true ? string.Empty : CustomMessages.GenericErrorMessage, Response = response }, JsonRequestBehavior.AllowGet)); } }
public bool AddAccountType(tbl_Account_Types row) { try { using (var db = new SoneriCISEntities()) { if (db.tbl_Account_Types.Where(e => e.Name.ToLower() == row.Name.ToLower()).Any()) { throw new CustomException("Account type name already exists!"); } db.tbl_Account_Types.Add(row); db.SaveChanges(); } return(true); } catch (Exception ex) { return(false); } }