public HttpResponseMessage AddAccountArticleType(Entities.MstAccountArticleType objAccountArticleType)
        {
            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 currentUserLock = currentUser.FirstOrDefault().IsLocked;

                    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)
                        {
                            var account = from d in db.MstAccounts
                                          where d.IsLocked == true &&
                                          d.Id == objAccountArticleType.AccountId
                                          select d;

                            if (account.Any())
                            {
                                Data.MstAccountArticleType newAccountArticleType = new Data.MstAccountArticleType
                                {
                                    AccountId     = objAccountArticleType.AccountId,
                                    ArticleTypeId = objAccountArticleType.ArticleTypeId
                                };

                                db.MstAccountArticleTypes.InsertOnSubmit(newAccountArticleType);
                                db.SubmitChanges();

                                String newObject = at.GetObjectString(newAccountArticleType);
                                at.InsertAuditTrail(currentUser.FirstOrDefault().Id, GetType().Name, MethodBase.GetCurrentMethod().Name, "NA", newObject);

                                return(Request.CreateResponse(HttpStatusCode.OK));
                            }
                            else
                            {
                                return(Request.CreateResponse(HttpStatusCode.NotFound, "Account not exist."));
                            }
                        }
                        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."));
            }
        }
Exemple #2
0
        public HttpResponseMessage AddAccountArticleType(Entities.MstAccountArticleType objAccountArticleType)
        {
            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)
                        {
                            var account = from d in db.MstAccounts
                                          where d.IsLocked == true
                                          select d;

                            if (account.Any())
                            {
                                Data.MstAccountArticleType newAccountArticleType = new Data.MstAccountArticleType
                                {
                                    AccountId     = objAccountArticleType.AccountId,
                                    ArticleTypeId = objAccountArticleType.ArticleTypeId
                                };

                                db.MstAccountArticleTypes.InsertOnSubmit(newAccountArticleType);
                                db.SubmitChanges();

                                return(Request.CreateResponse(HttpStatusCode.OK));
                            }
                            else
                            {
                                return(Request.CreateResponse(HttpStatusCode.NotFound, "No account found. Please setup more account for all chart of account tables."));
                            }
                        }
                        else
                        {
                            return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. You have no rights to add new account article type in this chart of account page."));
                        }
                    }
                    else
                    {
                        return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. You have no access in this chart of account 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."));
            }
        }
Exemple #3
0
        public HttpResponseMessage UpdateAccountArticleType(Entities.MstAccountArticleType objAccountArticleType, 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 accountArticleType = from d in db.MstAccountArticleTypes
                                                     where d.Id == Convert.ToInt32(id)
                                                     select d;

                            if (accountArticleType.Any())
                            {
                                var account = from d in db.MstAccounts
                                              where d.IsLocked == true &&
                                              d.Id == objAccountArticleType.AccountId
                                              select d;

                                if (account.Any())
                                {
                                    var updateAccountArticleType = accountArticleType.FirstOrDefault();
                                    updateAccountArticleType.AccountId     = objAccountArticleType.AccountId;
                                    updateAccountArticleType.ArticleTypeId = objAccountArticleType.ArticleTypeId;

                                    db.SubmitChanges();

                                    return(Request.CreateResponse(HttpStatusCode.OK));
                                }
                                else
                                {
                                    return(Request.CreateResponse(HttpStatusCode.NotFound, "Account not exist."));
                                }
                            }
                            else
                            {
                                return(Request.CreateResponse(HttpStatusCode.NotFound, "This account article 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."));
            }
        }