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

                Data.MstAccountCashFlow newAccountCashFlow = new Data.MstAccountCashFlow();
                newAccountCashFlow.AccountCashFlowCode = accountCashFlow.AccountCashFlowCode;
                newAccountCashFlow.AccountCashFlow = accountCashFlow.AccountCashFlow;
                newAccountCashFlow.IsLocked = accountCashFlow.IsLocked;
                newAccountCashFlow.CreatedById = userId;
                newAccountCashFlow.CreatedDateTime = DateTime.Now;
                newAccountCashFlow.UpdatedById = userId;
                newAccountCashFlow.UpdatedDateTime = DateTime.Now;

                db.MstAccountCashFlows.InsertOnSubmit(newAccountCashFlow);
                db.SubmitChanges();

                return newAccountCashFlow.Id;
            }
            catch
            {
                return 0;
            }
        }
Esempio n. 2
0
        public Int32 insertAccountCashFlow(Models.MstAccountCashFlow accountCashFlow)
        {
            try
            {
                var userId = (from d in db.MstUsers where d.UserId == User.Identity.GetUserId() select d.Id).SingleOrDefault();

                Data.MstAccountCashFlow newAccountCashFlow = new Data.MstAccountCashFlow();
                newAccountCashFlow.AccountCashFlowCode = accountCashFlow.AccountCashFlowCode;
                newAccountCashFlow.AccountCashFlow     = accountCashFlow.AccountCashFlow;
                newAccountCashFlow.IsLocked            = accountCashFlow.IsLocked;
                newAccountCashFlow.CreatedById         = userId;
                newAccountCashFlow.CreatedDateTime     = DateTime.Now;
                newAccountCashFlow.UpdatedById         = userId;
                newAccountCashFlow.UpdatedDateTime     = DateTime.Now;

                db.MstAccountCashFlows.InsertOnSubmit(newAccountCashFlow);
                db.SubmitChanges();

                return(newAccountCashFlow.Id);
            }
            catch
            {
                return(0);
            }
        }
        public HttpResponseMessage AddAccountCashFlow(Entities.MstAccountCashFlow objAccountCashFlow)
        {
            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.MstAccountCashFlow newAccountCashFlow = new Data.MstAccountCashFlow
                            {
                                AccountCashFlowCode = objAccountCashFlow.AccountCashFlowCode,
                                AccountCashFlow     = objAccountCashFlow.AccountCashFlow,
                                IsLocked            = true,
                                CreatedById         = currentUserId,
                                CreatedDateTime     = DateTime.Now,
                                UpdatedById         = currentUserId,
                                UpdatedDateTime     = DateTime.Now
                            };

                            db.MstAccountCashFlows.InsertOnSubmit(newAccountCashFlow);
                            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."));
            }
        }