Esempio n. 1
0
        public static GetExpensesResponse GetExpenseByActionId(IdRequest request)
        {
            GetExpensesResponse response = new GetExpensesResponse();
            ExpenseAppEntities  entity   = new ExpenseAppEntities();

            try
            {
                response.ExpenseDto = from expense in entity.Expenses
                                      where expense.LastExpenseActionId == request.ID
                                      select new ExpenseDto
                {
                    ID          = expense.ID,
                    CreatedDate = expense.CreatedDate,
                    TotalAmount = expense.TotalAmount,
                    UserId      = expense.UserId,
                    UserName    = expense.User.FullName
                };

                if (response.ExpenseDto == null)
                {
                    response.IsSuccess = false;
                }

                response.IsSuccess = true;
            }
            catch (Exception ex)
            {
                response.IsSuccess = false;
                log.Error("Get Expense By UserId Unsuccessful", ex);
            }

            return(response);
        }
Esempio n. 2
0
        public static GetExpensesResponse GetExpenseByUserId(int userId)
        {
            GetExpensesResponse response = new GetExpensesResponse();
            ExpenseAppEntities  entity   = new ExpenseAppEntities();

            try
            {
                response.ExpenseDto = from expense in entity.Expenses.Where(e => e.UserId == userId)
                                      //where expense.UserId == userId
                                      //from user in Entity.Users.Where(user => user.ID == expense.UserId)
                                      //from history in Entity.ExpenseHistories.Where(history => history.ExpenseStatusId == expense.LastExpenseActionId)
                                      from status in entity.ExpenseStatus.Where(status => status.ID == expense.LastExpenseActionId)
                                      select new ExpenseDto
                {
                    ID                  = expense.ID,
                    CreatedDate         = expense.CreatedDate,
                    TotalAmount         = expense.TotalAmount,
                    UserId              = expense.UserId,
                    LastExpenseActionId = expense.LastExpenseActionId,
                    CurrentStatus       = status.StatusName
                };

                var user = (from u in entity.Users
                            where u.ID == userId
                            select u).Single();
                response.UserId = user.ID;

                //test
                //var expense = Entity.Expenses
                //            .Include(e => e.User)
                //            .Include(e => e.ExpenseHistories)
                //            .FirstOrDefault(x => x.ID == 4);
                //var a = expense.ExpenseHistories.LastOrDefault().ExpenseStatusId;

                response.IsSuccess = response.ExpenseDto == null ? false : true;
            }
            catch (Exception ex)
            {
                response.IsSuccess = false;
                log.Error("Get Expense By UserId Unsuccessful", ex);
            }
            return(response);
        }