Exemplo n.º 1
0
        public HttpResponseMessage AddAccountCategory(Entities.MstAccountCategory objAccountCategory)
        {
            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("ChartOfAccounts")
                                    select d;

                    if (userForms.Any())
                    {
                        if (userForms.FirstOrDefault().CanAdd)
                        {
                            Data.MstAccountCategory newAccountCategory = new Data.MstAccountCategory
                            {
                                AccountCategoryCode = objAccountCategory.AccountCategoryCode,
                                AccountCategory     = objAccountCategory.AccountCategory,
                                IsLocked            = true,
                                CreatedById         = currentUserId,
                                CreatedDateTime     = DateTime.Now,
                                UpdatedById         = currentUserId,
                                UpdatedDateTime     = DateTime.Now
                            };

                            db.MstAccountCategories.InsertOnSubmit(newAccountCategory);
                            db.SubmitChanges();

                            return(Request.CreateResponse(HttpStatusCode.OK));
                        }
                        else
                        {
                            return(Request.CreateResponse(HttpStatusCode.NotFound, "No rights."));
                        }
                    }
                    else
                    {
                        return(Request.CreateResponse(HttpStatusCode.NotFound, "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."));
            }
        }
Exemplo n.º 2
0
        public HttpResponseMessage UpdateAccountCategory(Entities.MstAccountCategory objAccountCategory, 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("ChartOfAccounts")
                                    select d;

                    if (userForms.Any())
                    {
                        if (userForms.FirstOrDefault().CanEdit)
                        {
                            var accountCategory = from d in db.MstAccountCategories
                                                  where d.Id == Convert.ToUInt32(id)
                                                  select d;

                            if (accountCategory.Any())
                            {
                                var updateAccountCategory = accountCategory.FirstOrDefault();

                                updateAccountCategory.AccountCategoryCode = objAccountCategory.AccountCategoryCode;
                                updateAccountCategory.AccountCategory     = objAccountCategory.AccountCategory;
                                updateAccountCategory.IsLocked            = true;
                                updateAccountCategory.UpdatedById         = currentUserId;
                                updateAccountCategory.UpdatedDateTime     = DateTime.Now;

                                db.SubmitChanges();

                                return(Request.CreateResponse(HttpStatusCode.OK));
                            }
                            else
                            {
                                return(Request.CreateResponse(HttpStatusCode.NotFound, "This account cash flow detail is no longer available."));
                            }
                        }
                        else
                        {
                            return(Request.CreateResponse(HttpStatusCode.NotFound, "No rights."));
                        }
                    }
                    else
                    {
                        return(Request.CreateResponse(HttpStatusCode.NotFound, "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."));
            }
        }