Ejemplo n.º 1
0
        public static void saveexpense(dynamic data)
        {
            ExpensesEntities db                = new ExpensesEntities();
            Expense          newExpense        = new Expense();
            ExpenseHistory   newExpenseHistory = new ExpenseHistory();



            newExpense.UserId      = data.expensedata.CurrentUserId;
            newExpense.CreatedDate = DateTime.Now;
            newExpense.TotalAmount = data.expensedata.TotalAmount;

            db.Expense.Add(newExpense);
            db.SaveChanges();

            newExpenseHistory.ExpenseId        = db.Expense.ToList().Last().Id;
            newExpenseHistory.ExpenseStatusId  = 2;
            newExpenseHistory.Createdby_UserId = data.expensedata.CurrentUserId;

            db.ExpenseHistory.Add(newExpenseHistory);
            db.SaveChanges();

            foreach (var item in data.expenseitemdata)
            {
                Data.ExpenseItem newExpenseItem = new Data.ExpenseItem();
                newExpenseItem.ExpenseId   = db.Expense.ToList().Last().Id;
                newExpenseItem.ExpenseType = item.ExpenseType;
                newExpenseItem.Description = item.Description;
                newExpenseItem.Amount      = item.Amount;
                newExpenseItem.ExpenseDate = item.ExpenseDate;
                db.ExpenseItem.Add(newExpenseItem);
            }

            db.SaveChanges();
        }
        public static void saveExpenseItem(Data.ExpenseItem expenseItem)
        {
            ExpensesEntities db = new ExpensesEntities();

            expenseItem.ExpenseId = db.Expense.ToList().Last().Id;
            db.ExpenseItem.Add(expenseItem);

            db.SaveChanges();
        }
        public static bool PayForm(string Id)
        {
            ExpensesEntities db = new ExpensesEntities();

            int newId = Convert.ToInt32(Id);

            (from ExpenseHistory in db.ExpenseHistory.Where(e => e.ExpenseId == newId) select ExpenseHistory).SingleOrDefault().ExpenseStatusId = 4;
            db.SaveChanges();

            return(true);
        }
Ejemplo n.º 4
0
        public static Expense deleteexpensebyid(int id)
        {
            ExpensesEntities db      = new ExpensesEntities();
            Expense          expense = db.Expense.Find(id);

            if (expense != null)
            {
                db.Expense.Remove(expense);
                db.SaveChanges();
            }

            return(expense);
        }
        public static bool ConfirmReject(dynamic data)
        {
            ExpensesEntities db = new ExpensesEntities();

            int    newId            = Convert.ToInt32(data.DetailId);
            string RejectDefinition = data.RejectDefiniton.ToString();

            (from ExpenseHistory in db.ExpenseHistory.Where(e => e.ExpenseId == newId) select ExpenseHistory).SingleOrDefault().ExpenseStatusId  = 5;
            (from ExpenseHistory in db.ExpenseHistory.Where(e => e.ExpenseId == newId) select ExpenseHistory).SingleOrDefault().RejectDefinition = RejectDefinition;
            db.SaveChanges();

            return(true);
        }
        public static ExpenseItem deleteexpenseItembyid(int id)
        {
            ExpensesEntities db = new ExpensesEntities();

            Data.ExpenseItem expenseItem = db.ExpenseItem.Find(id);

            if (expenseItem != null)
            {
                db.ExpenseItem.Remove(expenseItem);
                db.SaveChanges();
            }

            return(expenseItem);
        }
Ejemplo n.º 7
0
        //Manager and Accountant Expense list
        public static IEnumerable <ExpenseDomain> GetExpenseByStatus(string CurrentUserRole)
        {
            ExpensesEntities db = new ExpensesEntities();

            if (CurrentUserRole == "Manager") //manager
            {
                var entities = (from h in db.ExpenseHistory
                                join e in db.Expense on h.ExpenseId equals e.Id
                                where h.ExpenseStatusId == 2
                                select new ExpenseDomain
                {
                    ID = e.Id,
                    CreatedTime = e.CreatedDate,
                    UserId = e.UserId,
                    UserName = (from a in db.AspNetUsers.Where(k => k.Id == e.UserId) select a.UserName).FirstOrDefault(),
                    StatusName = (from h in db.ExpenseHistory.Where(h => h.ExpenseId == e.Id)
                                  from s in db.ExpenseStatus.Where(s => s.Id == h.ExpenseStatusId)
                                  select s.ExpenseStatusName).FirstOrDefault(),
                    TotalAmount = e.TotalAmount
                }).ToList();


                return(entities);
            }
            else //accountant
            {
                var entities = (from h in db.ExpenseHistory
                                join e in db.Expense on h.ExpenseId equals e.Id
                                where h.ExpenseStatusId == 3
                                select new ExpenseDomain
                {
                    ID = e.Id,
                    CreatedTime = e.CreatedDate,
                    UserId = e.UserId,
                    UserName = (from a in db.AspNetUsers.Where(k => k.Id == e.UserId) select a.UserName).FirstOrDefault(),
                    StatusName = (from h in db.ExpenseHistory.Where(h => h.ExpenseId == e.Id)
                                  from s in db.ExpenseStatus.Where(s => s.Id == h.ExpenseStatusId)
                                  select s.ExpenseStatusName).FirstOrDefault(),
                    TotalAmount = e.TotalAmount
                }).ToList();


                return(entities);
            }
        }
Ejemplo n.º 8
0
        //Employee expense list
        public static IEnumerable <ExpenseDomain> GetExpenseByUserId(string CurrentUserId)
        {
            ExpensesEntities db = new ExpensesEntities();

            var replay = (from expense in db.Expense.Where(e => e.UserId == CurrentUserId)
                          select new ExpenseDomain
            {
                ID = expense.Id,
                CreatedTime = expense.CreatedDate,
                UserId = expense.UserId,
                UserName = (from a in db.AspNetUsers.Where(e => e.Id == expense.UserId) select a.UserName).FirstOrDefault(),
                StatusName = (from h in db.ExpenseHistory.Where(h => h.ExpenseId == expense.Id)
                              from s in db.ExpenseStatus.Where(s => s.Id == h.ExpenseStatusId)
                              select s.ExpenseStatusName).FirstOrDefault(),
                TotalAmount = expense.TotalAmount
            }).ToList();


            return(replay);
        }
Ejemplo n.º 9
0
        public static bool updateexpense(Expense expense, int id)
        {
            ExpensesEntities db = new ExpensesEntities();

            db.Entry(expense).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ExpenseExists(id))
                {
                    return(false);
                }
                else
                {
                    throw;
                }
            }
            return(true);
        }
        //kullanımda
        public static IEnumerable <ExpensesItemDomain> getallrecords(string Id)
        {
            ExpensesEntities db = new ExpensesEntities();

            int newId = Convert.ToInt32(Id);

            var replay = (from expenseItem in db.ExpenseItem.Where(e => e.ExpenseId == newId)
                          select new ExpensesItemDomain
            {
                ID = expenseItem.Id,
                ExpenseId = expenseItem.ExpenseId,
                ExpenseType = expenseItem.ExpenseType,
                Description = expenseItem.Description,
                //ExpenseDate = expenseItem.ExpenseDate,
                Amount = expenseItem.Amount
            }).ToList();


            return(replay);

            //ExpensesEntities db = new ExpensesEntities();
            //return db.ExpenseItem;
        }
Ejemplo n.º 11
0
        public static IQueryable <Expense> getallrecords()
        {
            ExpensesEntities db = new ExpensesEntities();



            //var a = HttpContext.Current.Session["CurrentUserRole"];

            //if (role == "Manager")
            //{

            //}
            //else if(role == "Employee")
            //{
            //    return (from u in db.Expense where u.UserId == userid select u);

            //}
            //else if(role == "Accountant")
            //{

            //}

            return(db.Expense);
        }
Ejemplo n.º 12
0
        public static string GetUserRole(string id)
        {
            ExpensesEntities db = new ExpensesEntities();

            return(db.AspNetRoles.Find(db.AspNetUsers.Find(id).RoleId).Name);
        }
Ejemplo n.º 13
0
        public static Expense getexpensebyid(int id)
        {
            ExpensesEntities db = new ExpensesEntities();

            return(db.Expense.Find(id));
        }
Ejemplo n.º 14
0
        public static bool ExpenseExists(int id)
        {
            ExpensesEntities db = new ExpensesEntities();

            return(db.Expense.Count(e => e.Id == id) > 0);
        }
        //



        public static ExpenseItem getExpenseItembyid(int id)
        {
            ExpensesEntities db = new ExpensesEntities();

            return(db.ExpenseItem.Find(id));
        }