Пример #1
0
        public HttpResponseMessage putAccount(String id, Entities.MstAccount account)
        {
            try
            {
                var accounts = from d in db.MstAccounts where d.Id == Convert.ToInt32(id) select d;
                if (accounts.Any())
                {
                    var updateAccount = accounts.FirstOrDefault();
                    updateAccount.Code        = account.Code;
                    updateAccount.Account     = account.Account;
                    updateAccount.IsLocked    = account.IsLocked;
                    updateAccount.AccountType = account.AccountType;
                    db.SubmitChanges();

                    return(Request.CreateResponse(HttpStatusCode.OK));
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound));
                }
            }
            catch (Exception e)
            {
                // Debug.WriteLine(e);
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
        }
Пример #2
0
        public HttpResponseMessage AddAccount(Entities.MstAccount objAccount)
        {
            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 accountTypes = from d in db.MstAccountTypes
                                               where d.IsLocked == true
                                               select d;

                            if (accountTypes.Any())
                            {
                                var accountCashFlows = from d in db.MstAccountCashFlows
                                                       where d.IsLocked == true
                                                       select d;

                                if (accountCashFlows.Any())
                                {
                                    Data.MstAccount newAccount = new Data.MstAccount
                                    {
                                        AccountCode       = objAccount.AccountCode,
                                        Account           = objAccount.Account,
                                        AccountTypeId     = objAccount.AccountTypeId,
                                        AccountCashFlowId = objAccount.AccountCashFlowId,
                                        IsLocked          = objAccount.IsLocked,
                                        CreatedById       = currentUserId,
                                        CreatedDateTime   = DateTime.Now,
                                        UpdatedById       = currentUserId,
                                        UpdatedDateTime   = DateTime.Now
                                    };

                                    db.MstAccounts.InsertOnSubmit(newAccount);
                                    db.SubmitChanges();

                                    return(Request.CreateResponse(HttpStatusCode.OK));
                                }
                                else
                                {
                                    return(Request.CreateResponse(HttpStatusCode.NotFound, "No account cash flow found. Please setup more account cash flows for all chart of account tables."));
                                }
                            }
                            else
                            {
                                return(Request.CreateResponse(HttpStatusCode.NotFound, "No account type found. Please setup more account types for all chart of account tables."));
                            }
                        }
                        else
                        {
                            return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. You have no rights to add new account 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."));
            }
        }
Пример #3
0
        public HttpResponseMessage UpdateAccount(Entities.MstAccount objAccount, 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 accountTypes = from d in db.MstAccountTypes
                                               where d.IsLocked == true
                                               select d;

                            if (accountTypes.Any())
                            {
                                var accountCashFlows = from d in db.MstAccountCashFlows
                                                       where d.IsLocked == true
                                                       select d;

                                if (accountCashFlows.Any())
                                {
                                    var account = from d in db.MstAccounts
                                                  where d.Id == Convert.ToInt32(id)
                                                  select d;

                                    if (account.Any())
                                    {
                                        var updateAccount = account.FirstOrDefault();
                                        updateAccount.AccountCode       = objAccount.AccountCode;
                                        updateAccount.Account           = objAccount.Account;
                                        updateAccount.AccountTypeId     = objAccount.AccountTypeId;
                                        updateAccount.AccountCashFlowId = objAccount.AccountCashFlowId;
                                        updateAccount.IsLocked          = objAccount.IsLocked;
                                        updateAccount.UpdatedById       = currentUserId;
                                        updateAccount.UpdatedDateTime   = DateTime.Now;

                                        db.SubmitChanges();

                                        return(Request.CreateResponse(HttpStatusCode.OK));
                                    }
                                    else
                                    {
                                        return(Request.CreateResponse(HttpStatusCode.NotFound, "This account detail is no longer exist in the server."));
                                    }
                                }
                                else
                                {
                                    return(Request.CreateResponse(HttpStatusCode.NotFound, "No account cash flow found. Please setup more account cash flows for all chart of account tables."));
                                }
                            }
                            else
                            {
                                return(Request.CreateResponse(HttpStatusCode.NotFound, "No account type found. Please setup more account types for all chart of account tables."));
                            }
                        }
                        else
                        {
                            return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. You have no rights to edit and update account 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."));
            }
        }
Пример #4
0
        public HttpResponseMessage AddAccount(Entities.MstAccount objAccount)
        {
            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 accountTypes = from d in db.MstAccountTypes
                                               where d.IsLocked == true &&
                                               d.Id == objAccount.AccountTypeId
                                               select d;

                            if (accountTypes.Any())
                            {
                                var accountCashFlows = from d in db.MstAccountCashFlows
                                                       where d.IsLocked == true &&
                                                       d.Id == objAccount.AccountCashFlowId
                                                       select d;

                                if (accountCashFlows.Any())
                                {
                                    Data.MstAccount newAccount = new Data.MstAccount
                                    {
                                        AccountCode       = objAccount.AccountCode,
                                        Account           = objAccount.Account,
                                        AccountTypeId     = objAccount.AccountTypeId,
                                        AccountCashFlowId = objAccount.AccountCashFlowId,
                                        IsLocked          = true,
                                        CreatedById       = currentUserId,
                                        CreatedDateTime   = DateTime.Now,
                                        UpdatedById       = currentUserId,
                                        UpdatedDateTime   = DateTime.Now
                                    };

                                    db.MstAccounts.InsertOnSubmit(newAccount);
                                    db.SubmitChanges();

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

                                    return(Request.CreateResponse(HttpStatusCode.OK));
                                }
                                else
                                {
                                    return(Request.CreateResponse(HttpStatusCode.NotFound, "Account cash flow not found."));
                                }
                            }
                            else
                            {
                                return(Request.CreateResponse(HttpStatusCode.NotFound, "Account type not found."));
                            }
                        }
                        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."));
            }
        }