public HttpResponseMessage UpdateArticleGroupBranch(Entities.MstArticleGroupBranch objArticleGroupBranch, String id) { try { var currentUser = from d in db.MstUsers where d.UserId == User.Identity.GetUserId() select d; if (currentUser.Any()) { var currentUserId = currentUser.FirstOrDefault().Id; var userForms = from d in db.MstUserForms where d.UserId == currentUserId && d.SysForm.FormName.Equals("SystemTables") select d; if (userForms.Any()) { if (userForms.FirstOrDefault().CanEdit) { var articleGroupBranch = from d in db.MstArticleGroupBranches where d.Id == Convert.ToInt32(id) select d; if (articleGroupBranch.Any()) { String oldObject = at.GetObjectString(articleGroupBranch.FirstOrDefault()); var accounts = from d in db.MstAccounts.OrderBy(d => d.Account) where d.IsLocked == true select d; if (accounts.Any()) { var accountId = from d in accounts where d.Id == objArticleGroupBranch.AccountId select d; if (accountId.Any()) { var salesAccountId = from d in accounts where d.Id == objArticleGroupBranch.SalesAccountId select d; if (salesAccountId.Any()) { var costAccountId = from d in accounts where d.Id == objArticleGroupBranch.CostAccountId select d; if (costAccountId.Any()) { var assetAccountId = from d in accounts where d.Id == objArticleGroupBranch.AssetAccountId select d; if (assetAccountId.Any()) { var expenseAccountId = from d in accounts where d.Id == objArticleGroupBranch.ExpenseAccountId select d; if (expenseAccountId.Any()) { var updateArticleGroupBranch = articleGroupBranch.FirstOrDefault(); updateArticleGroupBranch.ArticleGroupId = objArticleGroupBranch.ArticleGroupId; updateArticleGroupBranch.BranchId = objArticleGroupBranch.BranchId; updateArticleGroupBranch.AccountId = objArticleGroupBranch.AccountId; updateArticleGroupBranch.SalesAccountId = objArticleGroupBranch.SalesAccountId; updateArticleGroupBranch.CostAccountId = objArticleGroupBranch.CostAccountId; updateArticleGroupBranch.AssetAccountId = objArticleGroupBranch.AssetAccountId; updateArticleGroupBranch.ExpenseAccountId = objArticleGroupBranch.ExpenseAccountId; db.SubmitChanges(); String newObject = at.GetObjectString(articleGroupBranch.FirstOrDefault()); at.InsertAuditTrail(currentUser.FirstOrDefault().Id, GetType().Name, MethodBase.GetCurrentMethod().Name, oldObject, newObject); return(Request.CreateResponse(HttpStatusCode.OK)); } else { return(Request.CreateResponse(HttpStatusCode.NotFound, "Expense account not found.")); } } else { return(Request.CreateResponse(HttpStatusCode.NotFound, "Asset account not found.")); } } else { return(Request.CreateResponse(HttpStatusCode.NotFound, "Cost account not found.")); } } else { return(Request.CreateResponse(HttpStatusCode.NotFound, "Sales account not found.")); } } else { return(Request.CreateResponse(HttpStatusCode.NotFound, "Account not found.")); } } else { return(Request.CreateResponse(HttpStatusCode.NotFound, "No account setup.")); } } else { return(Request.CreateResponse(HttpStatusCode.NotFound, "This article group branch detail is no longer available.")); } } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, "No rights.")); } } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, "No rights.")); } } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Theres no current user logged in.")); } } catch (Exception e) { Debug.WriteLine(e); return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Something's went wrong from the server.")); } }
public HttpResponseMessage AddArticleGroupBranch(Entities.MstArticleGroupBranch objArticleGroupBranch) { try { var currentUser = from d in db.MstUsers where d.UserId == User.Identity.GetUserId() select d; if (currentUser.Any()) { var currentUserId = currentUser.FirstOrDefault().Id; var userForms = from d in db.MstUserForms where d.UserId == currentUserId && d.SysForm.FormName.Equals("SystemTables") select d; if (userForms.Any()) { if (userForms.FirstOrDefault().CanAdd) { var accounts = from d in db.MstAccounts.OrderBy(d => d.Account) where d.IsLocked == true select d; if (accounts.Any()) { var accountId = from d in accounts where d.Id == objArticleGroupBranch.AccountId select d; if (accountId.Any()) { var salesAccountId = from d in accounts where d.Id == objArticleGroupBranch.SalesAccountId select d; if (salesAccountId.Any()) { var costAccountId = from d in accounts where d.Id == objArticleGroupBranch.CostAccountId select d; if (costAccountId.Any()) { var assetAccountId = from d in accounts where d.Id == objArticleGroupBranch.AssetAccountId select d; if (assetAccountId.Any()) { var expenseAccountId = from d in accounts where d.Id == objArticleGroupBranch.ExpenseAccountId select d; if (expenseAccountId.Any()) { Data.MstArticleGroupBranch newArticleGroupBranch = new Data.MstArticleGroupBranch { ArticleGroupId = objArticleGroupBranch.ArticleGroupId, BranchId = objArticleGroupBranch.BranchId, AccountId = objArticleGroupBranch.AccountId, SalesAccountId = objArticleGroupBranch.SalesAccountId, CostAccountId = objArticleGroupBranch.CostAccountId, AssetAccountId = objArticleGroupBranch.AssetAccountId, ExpenseAccountId = objArticleGroupBranch.ExpenseAccountId }; db.MstArticleGroupBranches.InsertOnSubmit(newArticleGroupBranch); db.SubmitChanges(); return(Request.CreateResponse(HttpStatusCode.OK, newArticleGroupBranch.Id)); } else { return(Request.CreateResponse(HttpStatusCode.NotFound, "Expense account not found.")); } } else { return(Request.CreateResponse(HttpStatusCode.NotFound, "Asset account not found.")); } } else { return(Request.CreateResponse(HttpStatusCode.NotFound, "Cost account not found.")); } } else { return(Request.CreateResponse(HttpStatusCode.NotFound, "Sales account not found.")); } } else { return(Request.CreateResponse(HttpStatusCode.NotFound, "Account not found.")); } } else { return(Request.CreateResponse(HttpStatusCode.NotFound, "No account setup.")); } } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, "No rights.")); } } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, "No rights.")); } } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Theres no current user logged in.")); } } catch (Exception e) { Debug.WriteLine(e); return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Something's went wrong from the server.")); } }