Beispiel #1
0
        public HttpResponseMessage AddAccountType(Entities.MstAccountType objAccountType)
        {
            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 accountCategories = from d in db.MstAccountCategories
                                                    where d.IsLocked == true &&
                                                    d.Id == objAccountType.AccountCategoryId
                                                    select d;

                            if (accountCategories.Any())
                            {
                                Data.MstAccountType newAccountType = new Data.MstAccountType
                                {
                                    AccountTypeCode        = objAccountType.AccountTypeCode,
                                    AccountType            = objAccountType.AccountType,
                                    AccountCategoryId      = objAccountType.AccountCategoryId,
                                    SubCategoryDescription = objAccountType.SubCategoryDescription,
                                    IsLocked        = true,
                                    CreatedById     = currentUserId,
                                    CreatedDateTime = DateTime.Now,
                                    UpdatedById     = currentUserId,
                                    UpdatedDateTime = DateTime.Now
                                };

                                db.MstAccountTypes.InsertOnSubmit(newAccountType);
                                db.SubmitChanges();

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

                                return(Request.CreateResponse(HttpStatusCode.OK));
                            }
                            else
                            {
                                return(Request.CreateResponse(HttpStatusCode.NotFound, "Account category not found."));
                            }
                        }
                        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 AddAccountType(Entities.MstAccountType objAccountType)
        {
            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 accountCategories = from d in db.MstAccountCategories
                                                    where d.IsLocked == true
                                                    select d;

                            if (accountCategories.Any())
                            {
                                Data.MstAccountType newAccountType = new Data.MstAccountType
                                {
                                    AccountTypeCode        = objAccountType.AccountTypeCode,
                                    AccountType            = objAccountType.AccountType,
                                    AccountCategoryId      = objAccountType.AccountCategoryId,
                                    SubCategoryDescription = objAccountType.SubCategoryDescription,
                                    IsLocked        = objAccountType.IsLocked,
                                    CreatedById     = currentUserId,
                                    CreatedDateTime = DateTime.Now,
                                    UpdatedById     = currentUserId,
                                    UpdatedDateTime = DateTime.Now
                                };

                                db.MstAccountTypes.InsertOnSubmit(newAccountType);
                                db.SubmitChanges();

                                return(Request.CreateResponse(HttpStatusCode.OK));
                            }
                            else
                            {
                                return(Request.CreateResponse(HttpStatusCode.NotFound, "No account category found. Please setup more account categories for all chart of account tables."));
                            }
                        }
                        else
                        {
                            return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. You have no rights to add new account 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."));
            }
        }
Beispiel #3
0
        public HttpResponseMessage UpdateAccountType(Entities.MstAccountType objAccountType, 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 accountCategories = from d in db.MstAccountCategories
                                                    where d.IsLocked == true &&
                                                    d.Id == objAccountType.AccountCategoryId
                                                    select d;

                            if (accountCategories.Any())
                            {
                                var accountType = from d in db.MstAccountTypes
                                                  where d.Id == Convert.ToUInt32(id)
                                                  select d;

                                if (accountType.Any())
                                {
                                    String oldObject = at.GetObjectString(accountType.FirstOrDefault());

                                    var updateAccountType = accountType.FirstOrDefault();
                                    updateAccountType.AccountTypeCode        = objAccountType.AccountTypeCode;
                                    updateAccountType.AccountType            = objAccountType.AccountType;
                                    updateAccountType.AccountCategoryId      = objAccountType.AccountCategoryId;
                                    updateAccountType.SubCategoryDescription = objAccountType.SubCategoryDescription;
                                    updateAccountType.IsLocked        = true;
                                    updateAccountType.UpdatedById     = currentUserId;
                                    updateAccountType.UpdatedDateTime = DateTime.Now;

                                    db.SubmitChanges();

                                    String newObject = at.GetObjectString(accountType.FirstOrDefault());
                                    at.InsertAuditTrail(currentUser.FirstOrDefault().Id, GetType().Name, MethodBase.GetCurrentMethod().Name, oldObject, newObject);

                                    return(Request.CreateResponse(HttpStatusCode.OK));
                                }
                                else
                                {
                                    return(Request.CreateResponse(HttpStatusCode.NotFound, "This account type detail is no longer available."));
                                }
                            }
                            else
                            {
                                return(Request.CreateResponse(HttpStatusCode.NotFound, "Account category not found."));
                            }
                        }
                        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 UpdateAccountType(Entities.MstAccountType objAccountType, 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 accountCategories = from d in db.MstAccountCategories
                                                    where d.IsLocked == true
                                                    select d;

                            if (accountCategories.Any())
                            {
                                var accountType = from d in db.MstAccountTypes
                                                  where d.Id == Convert.ToUInt32(id)
                                                  select d;

                                if (accountType.Any())
                                {
                                    var updateAccountType = accountType.FirstOrDefault();

                                    updateAccountType.AccountTypeCode        = objAccountType.AccountTypeCode;
                                    updateAccountType.AccountType            = objAccountType.AccountType;
                                    updateAccountType.AccountCategoryId      = objAccountType.AccountCategoryId;
                                    updateAccountType.SubCategoryDescription = objAccountType.SubCategoryDescription;
                                    updateAccountType.IsLocked        = objAccountType.IsLocked;
                                    updateAccountType.UpdatedById     = currentUserId;
                                    updateAccountType.UpdatedDateTime = DateTime.Now;

                                    db.SubmitChanges();

                                    return(Request.CreateResponse(HttpStatusCode.OK));
                                }
                                else
                                {
                                    return(Request.CreateResponse(HttpStatusCode.NotFound, "This account type detail is no longer exist in the server."));
                                }
                            }
                            else
                            {
                                return(Request.CreateResponse(HttpStatusCode.NotFound, "No account category found. Please setup more account categories for all chart of account tables."));
                            }
                        }
                        else
                        {
                            return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. You have no rights to edit and update account 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."));
            }
        }