public void ValidationChecks(GLAccountDto glAccountDto) { var glAccounts = _context.GlAccounts.Where(c => c.Name.Equals(glAccountDto.Name)).ToList(); if (glAccounts.Count > 0) { errorMessage = errorMessage + "GL Account name already exists"; } }
// [Authorize] public HttpResponseMessage EditGLAccount(Index index) { var id = index.Id; var glAccount = _context.GlAccounts.SingleOrDefault(c => c.Id == id); if (glAccount == null) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "No such GL Account Exists")); } var glAccountDto = new GLAccountDto() { Name = glAccount.Name, BranchId = glAccount.BranchId }; return(Request.CreateResponse(HttpStatusCode.OK, glAccountDto)); }
// [Authorize] public HttpResponseMessage UpdateGLAccount(GLAccountDto glAccountDto) { ValidationChecks(glAccountDto); if (!errorMessage.Equals("")) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, errorMessage)); } var id = glAccountDto.Id; var glAccount = _context.GlAccounts.SingleOrDefault(c => c.Id == id); if (glAccount == null) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "No such GL Account Exists")); } glAccount.Name = glAccountDto.Name; glAccount.BranchId = glAccountDto.BranchId; _context.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, "GL Account Updated Successfully")); }
public HttpResponseMessage CreateGLAccount(GLAccountDto glAccountDto) { ValidationChecks(glAccountDto); if (!errorMessage.Equals("")) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, errorMessage)); } var generalLedgerAccount = new GLAccount { GlCategoriesId = glAccountDto.CategoriesId, BranchId = glAccountDto.BranchId, Name = glAccountDto.Name, Code = getCode(glAccountDto.CategoriesId) }; //Mapper.Map(generalLedgerCategoryViewModel, generalLedgerCategory); _context.GlAccounts.Add(generalLedgerAccount); _context.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, "GL Account Created Successfully")); }