public HttpResponseMessage addArticleGroupBranch(Models.MstArticleGroupBranch articleGroupBranch) { try { Data.MstArticleGroupBranch newArticleGroupBranch = new Data.MstArticleGroupBranch(); newArticleGroupBranch.ArticleGroupId = articleGroupBranch.ArticleGroupId; newArticleGroupBranch.BranchId = articleGroupBranch.BranchId; newArticleGroupBranch.AccountId = articleGroupBranch.AccountId; newArticleGroupBranch.SalesAccountId = articleGroupBranch.SalesAccountId; newArticleGroupBranch.CostAccountId = articleGroupBranch.CostAccountId; newArticleGroupBranch.AssetAccountId = articleGroupBranch.AssetAccountId; newArticleGroupBranch.ExpenseAccountId = articleGroupBranch.ExpenseAccountId; db.MstArticleGroupBranches.InsertOnSubmit(newArticleGroupBranch); db.SubmitChanges(); return(Request.CreateResponse(HttpStatusCode.OK)); } catch { return(Request.CreateResponse(HttpStatusCode.InternalServerError)); } }
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(); String newObject = at.GetObjectString(newArticleGroupBranch); at.InsertAuditTrail(currentUser.FirstOrDefault().Id, GetType().Name, MethodBase.GetCurrentMethod().Name, "NA", newObject); 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.")); } }