Пример #1
0
        public async Task <Message> Execute(Message message,
                                            TelegramBotClient client,
                                            IExpenseRepository expenseRepository,
                                            IUserAccountRepository userAccountRepository,
                                            ICategoryRepository categoryRepository)
        {
            var chatId    = message.Chat.Id;
            var messageId = message.MessageId;

            expenseRepository.AddExpense(new Expense
            {
                UserAccount     = userAccountRepository.Accounts.FirstOrDefault(),
                ExpenseId       = 1,
                ExpenseDateTime = DateTime.Now,
                Category        = categoryRepository.Categories.FirstOrDefault(),
                Amount          = 13m,
                Description     = "just two Expense"
            });

            var tempStr = string.Format(SimpleTxtResponse.ExpenseTemplate,
                                        expenseRepository.Expenses.FirstOrDefault().Amount,
                                        expenseRepository.Expenses.FirstOrDefault().Category.CategoryName,
                                        expenseRepository.Expenses.FirstOrDefault().Description,
                                        "/del1");

            var outStr = string.Format(SimpleTxtResponse.LastExpenses, tempStr);

            //TODO: Telegram.Bot.Exceptions.ApiRequestException
            return(await client.SendTextMessageAsync(chatId, outStr));
        }
Пример #2
0
        public ActionResult <Expense> PostExpense(AddExpense addExpense)
        {
            Expense expense = _expenseRepository.AddExpense(addExpense);

            _expenseRepository.AddExpenseInfo(addExpense, expense);
            return(Ok());
        }
Пример #3
0
 public ActionResult AddMyExpense(ExpenseViewModel expenseViewModel)
 {
     if (ModelState.IsValid)
     {
         ExpenseMembers expenseMembers = new ExpenseMembers
         {
             Description     = expenseViewModel.Description,
             BudgetCategory  = expenseViewModel.SelectedBudget,
             SelectedGroupId = expenseViewModel.SelectedGroupId.ToList(),
             SpentAmount     = expenseViewModel.SpentAmount.Value,
             SpentBy         = expenseViewModel.SpentBy,
             SpentOn         = expenseViewModel.FormattedSpentDate,
             IncludedUsers   = expenseViewModel.IncludedUsers != null?expenseViewModel.IncludedUsers.ToList() : new List <string>(),
                                   ExcludedUsers = expenseViewModel.ExcludedUsers != null?expenseViewModel.ExcludedUsers.ToList() : new List <string>(),
                                                       CreatedBy = SessionUserId
         };
         expenseRepository.AddExpense(expenseMembers);
         return(RedirectToAction("AddMyExpense"));
     }
     else
     {
         DataSet expenseDetailsDataSet = expenseRepository.GetExpenseLookUp();
         expenseViewModel.Users            = expenseDetailsDataSet.Tables[0].LoadLookUps <string, int>();
         expenseViewModel.UserGroups       = expenseDetailsDataSet.Tables[1].LoadLookUps <string, int>();
         expenseViewModel.BudgetCategories = expenseDetailsDataSet.Tables[2].LoadLookUps <string, int>();
         expenseViewModel.SpentByUsers     = expenseDetailsDataSet.Tables[0].LoadLookUps <string, string>(SessionUserId);
         ModelState.AddModelError("", "Error saving your expense.");
         return(View("AddMyExpense", expenseViewModel));
     }
 }
Пример #4
0
        public IActionResult AddPost(ExpenseViewModel expenseViewModel)
        {
            var expensesList = _expense.GetExpenses();

            ViewBag.expenses      = expensesList;
            ViewBag.AccountTreeId = new SelectList(_Acctree.GetAccountTrees(), "Id", "DescriptionAr");
            if (expenseViewModel.AccountTreeId == null)
            {
                ModelState.AddModelError("", "الرجاء تحدد رقم الحساب في الشجرة");
            }
            if (expenseViewModel.Id == 0)
            {
                ModelState.Remove("Id");
                ModelState.Remove("AccountTreeId");
                if (ModelState.IsValid)
                {
                    var expense = _mapper.Map <Expense>(expenseViewModel);
                    _expense.AddExpense(expense);
                    _toastNotification.AddSuccessToastMessage("تم أضافةالمصروف بنجاح");
                    return(RedirectToAction(nameof(Index)));
                }
                return(View(nameof(Index), expenseViewModel));
            }
            else
            {
                if (ModelState.IsValid)
                {
                    var expensedetail = _mapper.Map <Expense>(expenseViewModel);
                    _expense.UpdateExpense(expenseViewModel.Id, expensedetail);
                    _toastNotification.AddSuccessToastMessage("تم تعديل البنك بنجاح");
                    return(RedirectToAction(nameof(Index)));
                }
                return(View(nameof(Index), expenseViewModel));
            }
        }
Пример #5
0
        public int AddExpense(NewExpenseVm newExp)
        {
            var exp = _mapper.Map <Expense>(newExp);
            int id  = _expenseRepo.AddExpense(exp);

            return(id);
        }
Пример #6
0
        public int AddExpense(ExpenseDTO dto)
        {
            int id = 0;

            try
            {
                log.Debug(ExpenseDTO.FormatExpenseDTO(dto));

                R_Expense t = ExpenseDTO.ConvertDTOtoEntity(dto);

                // add
                id            = Repository.AddExpense(t);
                dto.ExpenseId = id;

                log.Debug("result: 'success', id: " + id);
            }
            catch (System.Exception e)
            {
                // error
                log.Error(e.ToString());

                throw;
            }

            return(id);
        }
        public async Task <IActionResult> AddExpense([FromBody] Expense expense)
        {
            Console.WriteLine("[Add Expense] " + expense);

            if (expense == null || !ModelState.IsValid)
            {
                return(BadRequest(new ErrorModel <Object>(ProjectCodes.Form_Generic_Error)));
            }

            Console.WriteLine("[ExpenseControlelr][Add Expense]" + expense.ExpenseId);

            try {
                if (string.IsNullOrEmpty(expense.UserId) || !await _userRepository.Exists(expense.UserId))
                {
                    return(BadRequest(new ErrorModel <Object>(ProjectCodes.User_Not_Found)));
                }

                expense = TimeUtils.GetExpenseUtc(expense);
                await _expenseRepository.AddExpense(expense);

                return(Ok(expense));
            }
            catch (Exception e) {
                Console.WriteLine(e);
                return(BadRequest(new ErrorModel <Object>(ProjectCodes.Generic_Error)));
            }
        }
Пример #8
0
        public IActionResult AddExpense(Guid categoryId, [FromBody] ExpenseForAddDto expense)
        {
            if (expense == null)
            {
                return(BadRequest());
            }

            if (!_budgetCategoryRepository.CategoryExists(categoryId))
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var budgetCategory = _budgetCategoryRepository.GetCategoryById(categoryId);

            var expenseToCreate = Mapper.Map <ExpenseEntity>(expense);

            expenseToCreate.BudgetCategory = budgetCategory;

            _expenseRepository.AddExpense(expenseToCreate);

            if (!_expenseRepository.SaveChanges())
            {
                return(StatusCode(500, "The server was unable to handle your request."));
            }

            var createdExpenseForReturn = Mapper.Map <ExpenseDto>(expenseToCreate);

            return(CreatedAtRoute("GetExpenseById", new
                                  { id = createdExpenseForReturn.ExpenseId }, createdExpenseForReturn));
        }
Пример #9
0
 public ActionResult Create([Bind("Id,Name,Payee,Amount")] Expense expense)
 {
     if (ModelState.IsValid)
     {
         _expenseRepository.AddExpense(expense);
         return(RedirectToAction(nameof(Index)));
     }
     return(View(expense));
 }
Пример #10
0
        public async Task <Message> Execute(Message message,
                                            TelegramBotClient client)
        {
            _chatId = message.Chat.Id;
            _msg    = message.Text;
            _usrId  = message.From.Id;
            _client = client;

            if (!_userAccountRepository.GetUser(_usrId,
                                                out UserAccount userAccount))
            {
                throw new UserNotFoundException(_msg, _usrId);
            }

            Regex regex = new Regex(_rgxString);
            Match match = regex.Match(_msg);

            if (match.Success && decimal.TryParse(match.Value, out decimal summ))
            {
                var cmdTxtContent = (match.NextMatch().Value).Split(" ",
                                                                    StringSplitOptions.RemoveEmptyEntries);

                var categoryName = cmdTxtContent[0];
                var description  = (_msg.Split(categoryName)[1]).Trim();

                var category = _categoryRepository
                               .GetCategory(userAccount, categoryName);

                if (category == null)
                {
                    category = _categoryRepository
                               .GetCategory(userAccount, "other");
                }

                _expenseRepository.AddExpense(new Expense
                {
                    ExpenseId = _expenseRepository.Expenses
                                .Where(e => e.UserAccount.UserId == _usrId)
                                .Select(e => e.ExpenseId)
                                .OrderByDescending(e => e)
                                .FirstOrDefault() + 1,
                    Amount          = summ,
                    Category        = category,
                    Description     = description,
                    ExpenseDateTime = DateTime.Now,
                    UserAccount     = userAccount,
                });
            }
            else
            {
                throw new BadExpenseExeption(_msg);
            }

            return(await client.SendTextMessageAsync(_chatId,
                                                     string.Format(SimpleTxtResponse.AddExpense, "", "", _msg)));
        }
 public CommonResponseViewModel SaveExpense(ExpenseViewModel expenseVM)
 {
     if (expenseVM.id > 0)
     {
         return(_expenseRepository.UpdateExpense(expenseVM));
     }
     else
     {
         return(_expenseRepository.AddExpense(expenseVM));
     }
 }
Пример #12
0
 public Task <bool> AddExpense(ExpenseForCreationDto expenseForCreationDto)
 {
     foreach (var assetId in expenseForCreationDto.AssetIds)
     {
         var expense = new Expense();
         expense.AssetId     = assetId;
         expense.DateCreated = expenseForCreationDto.ExpenseDate;
         expense.Description = expenseForCreationDto.Description;
         expense.ExpenseType = (ExpenseTypeEnum)expenseForCreationDto.ExpenseType;
         expense.Sum         = expenseForCreationDto.Amount / expenseForCreationDto.AssetIds.Count;
         _expenseRepository.AddExpense(expense);
     }
     return(_expenseRepository.SaveAll());
 }
Пример #13
0
        public IActionResult CreateExpense([FromBody] Expense Expense)
        {
            if (Expense == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var createdExpense = _expenseRepository.AddExpense(Expense);

            return(Created("Expense", createdExpense));
        }
        public ActionResult List(ExpenseCart cart, string description)
        {
            var userId = User.Identity.GetUserId();

            var expense = cart.GetExpense();

            expense.UserId      = userId;
            expense.ModifyDate  = DateTime.Now;
            expense.ExpenseDate = DateTime.Now;
            expense.Description = description;
            expense.ModifyBy    = User.Identity.GetUserName();
            expense.Status      = Status.WaitingApprove;

            VPExpenseHistory history = new VPExpenseHistory
            {
                ModifyBy   = User.Identity.GetUserName(),
                ModifyDate = DateTime.Now
            };

            ExpenseRepository.AddExpense(expense);
            cart.Clear();
            return(RedirectToAction("Index", "Home"));
        }
Пример #15
0
 public async Task AddExpense(ExpenseReport expense)
 {
     await _expenseRepository.AddExpense(expense);
 }
 public ActionResult AddExpense(Expenses expenses)
 {
     expenses.UserId = User.Identity.GetUserId();
     expenseRepository.AddExpense(expenses);
     return(RedirectToAction("Index"));
 }
Пример #17
0
        public IActionResult AddExpense([FromBody] Expense expense)
        {
            var expenseId = _expenseRepository.AddExpense(expense);

            return(Ok(expenseId));
        }
Пример #18
0
 public async Task AddExpenseAsync(ExpenseDto expense)
 {
     ValidateExpense(expense);
     await _expenseRepository.AddExpense(expense);
 }
Пример #19
0
 public async Task AddExpense(Guid userId, Expense expense)
 {
     await _repository.AddExpense(userId, expense);
 }