public Int32 insertAccountType(Models.MstAccountType accountType)
        {
            try
            {
                var userId = (from d in db.MstUsers where d.UserId == User.Identity.GetUserId() select d.Id).SingleOrDefault();

                Data.MstAccountType newAccountType = new Data.MstAccountType();
                newAccountType.AccountTypeCode        = accountType.AccountTypeCode;
                newAccountType.AccountType            = accountType.AccountType;
                newAccountType.AccountCategoryId      = accountType.AccountCategoryId;
                newAccountType.SubCategoryDescription = accountType.SubCategoryDescription;
                newAccountType.IsLocked        = accountType.IsLocked;
                newAccountType.CreatedById     = userId;
                newAccountType.CreatedDateTime = DateTime.Now;
                newAccountType.UpdatedById     = userId;
                newAccountType.UpdatedDateTime = DateTime.Now;

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

                return(newAccountType.Id);
            }
            catch
            {
                return(0);
            }
        }
        public Int32 insertAccountType(Models.MstAccountType accountType)
        {
            try
            {
                var userId = (from d in db.MstUsers where d.UserId == User.Identity.GetUserId() select d.Id).SingleOrDefault();

                Data.MstAccountType newAccountType = new Data.MstAccountType();
                newAccountType.AccountTypeCode = accountType.AccountTypeCode;
                newAccountType.AccountType = accountType.AccountType;
                newAccountType.AccountCategoryId = accountType.AccountCategoryId;
                newAccountType.SubCategoryDescription = accountType.SubCategoryDescription;
                newAccountType.IsLocked = accountType.IsLocked;
                newAccountType.CreatedById = userId;
                newAccountType.CreatedDateTime = DateTime.Now;
                newAccountType.UpdatedById = userId;
                newAccountType.UpdatedDateTime = DateTime.Now;

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

                return newAccountType.Id;
            }
            catch
            {
                return 0;
            }
        }
예제 #3
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."));
            }
        }