public HttpResponseMessage AddArticleGroup(Entities.MstArticleGroup objArticleGroup) { 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()) { Data.MstArticleGroup newArticleGroup = new Data.MstArticleGroup { ArticleGroup = objArticleGroup.ArticleGroup, ArticleTypeId = objArticleGroup.ArticleTypeId, AccountId = objArticleGroup.AccountId, SalesAccountId = objArticleGroup.SalesAccountId, CostAccountId = objArticleGroup.CostAccountId, AssetAccountId = objArticleGroup.AssetAccountId, ExpenseAccountId = objArticleGroup.ExpenseAccountId, IsLocked = true, CreatedById = currentUserId, CreatedDateTime = DateTime.Now, UpdatedById = currentUserId, UpdatedDateTime = DateTime.Now }; db.MstArticleGroups.InsertOnSubmit(newArticleGroup); db.SubmitChanges(); return(Request.CreateResponse(HttpStatusCode.OK, newArticleGroup.Id)); } else { return(Request.CreateResponse(HttpStatusCode.NotFound, "No account found. Please setup at least one account for article groups.")); } } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. You have no rights to add article group.")); } } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. You have no access for this system table page.")); } } 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 UpdateArticleGroup(Entities.MstArticleGroup objArticleGroup, 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 articleGroup = from d in db.MstArticleGroups where d.Id == Convert.ToInt32(id) select d; if (articleGroup.Any()) { var updateArticleGroup = articleGroup.FirstOrDefault(); updateArticleGroup.ArticleGroup = objArticleGroup.ArticleGroup; updateArticleGroup.ArticleTypeId = objArticleGroup.ArticleTypeId; updateArticleGroup.AccountId = objArticleGroup.AccountId; updateArticleGroup.SalesAccountId = objArticleGroup.SalesAccountId; updateArticleGroup.CostAccountId = objArticleGroup.CostAccountId; updateArticleGroup.AssetAccountId = objArticleGroup.AssetAccountId; updateArticleGroup.ExpenseAccountId = objArticleGroup.ExpenseAccountId; updateArticleGroup.IsLocked = true; updateArticleGroup.UpdatedById = currentUserId; updateArticleGroup.UpdatedDateTime = DateTime.Now; db.SubmitChanges(); return(Request.CreateResponse(HttpStatusCode.OK)); } else { return(Request.CreateResponse(HttpStatusCode.NotFound, "Data not found. These article group details are not found in the server.")); } } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. You have no rights to edit and update article group.")); } } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. You have no access for this system table page.")); } } 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.")); } }