Exemplo n.º 1
0
        public void CreateExpense(ExpenseViewModel expenseViewModel)
        {
            var expense = Mapper.Map <ExpenseViewModel, Expense_M>(expenseViewModel);

            _expenseRepository.Add(expense);
            SaveExpense();
        }
Exemplo n.º 2
0
 public bool Add(IExpense expense)
 {
     expense.Id          = _expenseRepository.Add(expense);
     expense.CreatedBy   = expense.UserId; //ToDo==>Add these Parameters in Sp
     expense.CreatedDate = DateTime.Now;
     return(_expenseMongoRepository.Add(expense));
 }
        public async Task HandleAsync(CreateExpenseCommand message, CancellationToken token = default(CancellationToken))
        {
            var expense = Expense.Create(message.ExpenseId, message.HouseholdId, message.ExpenseTypeId, message.Name,
                                         message.Description, message.Amount, message.Date, Period.Create(message.PeriodStart, message.PeriodEnd));

            _expenses.Add(expense);
            await _expenses.SaveChangesAsync(token);
        }
Exemplo n.º 4
0
 public void AddExpense(Expense e)
 {
     if (!expenseRepository.Any(x => x.ExpenseId == e.ExpenseId))
     {
         expenseRepository.Add(e);
         SaveExpense();
     }
 }
 public ActionResult Add(AddExpenseModel model)
 {
     if (ModelState.IsValid)
     {
         _repository.Add(model);
         return(RedirectToAction("List"));
     }
     return(View(model));
 }
Exemplo n.º 6
0
        public ActionResult Create(ExpenseModel expenseModel) //typ ExpenseModel parametr expenseModel
        {
            var claimsIdentity = (ClaimsIdentity)this.User.Identity;
            var claim          = claimsIdentity.FindFirst(System.Security.Claims.ClaimTypes.NameIdentifier);
            var userId         = claim.Value;

            expenseModel.UserId = userId;

            _expenseRepository.Add(expenseModel);

            return(RedirectToAction(nameof(Index)));
        }
Exemplo n.º 7
0
        public async Task <IHttpActionResult> Post(ExpenseViewModel expense)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _repository.Add(new Expense {
                CategoryId = expense.CategoryId, Amount = expense.Amount, Date = expense.Date
            });
            await _unitOfWork.SaveChangesAsync();

            return(CreatedAtRoute("DefaultApi", new { id = expense.Id }, expense));
        }
Exemplo n.º 8
0
        public IActionResult Create(ExpenseModel expense)
        {
            expense.Id = _expenseRepository.Add(new Expense()
            {
                UserId          = expense.UserId,
                Date            = expense.Date,
                Amount          = expense.Amount,
                Description     = expense.Description,
                IsShared        = expense.IsShared,
                SharedExpenseId = String.IsNullOrEmpty(expense.SharedExpenseId) == true ? null : expense.SharedExpenseId
            });

            return(CreatedAtRoute("GetExpense", new { id = expense.Id }, expense));
        }
        public void CreateExpense(Expense expense, long UserId)
        {
            // Get the employee
            Employee employee = employeeRepository.GetById(UserId);

            expense.Employee       = employee;
            expense.ApprovalStatus = Expense.Status.Submitted; // Always 'Submitted' when creating

            expenseRepository.Add(expense);

            //  Send Email to the managers

            //  Add a notification to be triggered in 48 hours
        }
Exemplo n.º 10
0
        public async Task <Expense> Add(decimal amount, string category)
        {
            var expense    = Expense.Create(amount, category);
            var categories = await _categories.GetAsync();

            if (categories.All(c => !c.Name.Equals(category)))
            {
                await _categories.Add(Category.Create(category));
            }

            await _expenses.Add(expense);

            return(expense);
        }
Exemplo n.º 11
0
        public async Task <IActionResult> CreateExpense([FromBody] ExpenseForCreateDto expenseForCreateDto)
        {
            var userId = HttpContext.GetUserIdFromToken();

            var expense = _mapper.Map <Expense>(expenseForCreateDto);

            expense.OwnerId = int.Parse(userId);

            await _repository.Add(expense);

            await _repository.SaveChangesAsync();

            var expenseDto = _mapper.Map <ExpenseDto>(expense);

            return(CreatedAtAction(nameof(GetExpense), new { id = expenseDto.Id }, expenseDto));
        }
Exemplo n.º 12
0
        public ICommandResult Execute(CreateOrUpdateExpenseCommand command)
        {
            var expense = this.mapper.Map <Expense>(command);

            if (expense.ExpenseId == 0)
            {
                expenseRepository.Add(expense);
            }
            else
            {
                expenseRepository.Update(expense);
            }

            unitOfWork.Commit();
            return(new CommandResult(true));
        }
Exemplo n.º 13
0
            public async Task <ExpenseToReturnDto> Handle(CreateExpenseCommand request, CancellationToken cancellationToken)
            {
                var expense = _mapper.Map <Expense>(request.ExpenseForCreationDto);
                await _expenseRepository.Add(expense);

                if (await _unitOfWorkRepository.SaveChanges() > 0)
                {
                    expense.Category = await _unitOfWorkRepository.Context.Categories.FindAsync(expense.CategoryId);

                    expense.Currency = await _unitOfWorkRepository.Context.Currencies.FindAsync(expense.CurrencyId);

                    return(_mapper.Map <ExpenseToReturnDto>(expense));
                }

                return(null);
            }
Exemplo n.º 14
0
        public async Task <CreateExpenseCommandResult> Handle(CreateExpenseCommand request, CancellationToken cancellationToken)
        {
            var expense = _mapper.Map <Expense>(request);

            if (expense.InValid)
            {
                return(_mapper.Map <CreateExpenseCommandResult>(expense));
            }

            _expenseRepository.Add(expense);
            expense.AddDomainEvent(new ExpenseCreatedDomainEvent(expense));

            await _expenseRepository.UnitOfWork.SaveChangesAsync(cancellationToken);

            return(_mapper.Map <CreateExpenseCommandResult>(expense));
        }
 public IActionResult Create(Expense expense)
 {
     if (string.IsNullOrEmpty(User.Identity.Name))
     {
         userName = "******";
     }
     else
     {
         userName = User.Identity.Name;
     }
     if (ModelState.IsValid)
     {
         expense.UserName = userName;
         Expense newExpense = _expenseRepository.Add(expense);
         return(RedirectToAction("Index"));
     }
     return(View());
 }
Exemplo n.º 16
0
        public Message Create(Expense expense)
        {
            Message msg = new Message();

            try
            {
                var model = expense.ToDalEntity();
                _expenseRepository.Add(model);
                _expenseRepository.SaveChanges();
                msg.StatusCode = 200;
                msg.Status     = "Expense Created Successfully!";
            }
            catch (Exception ex)
            {
                msg.StatusCode = 400;
                msg.Status     = "An error occured while creating expense.";
            }
            return(msg);
        }
Exemplo n.º 17
0
        public async Task <RequestResult <ExpenseDto> > Handle(AddExpense request, CancellationToken cancellationToken)
        {
            var result = new RequestResult <ExpenseDto>();

            var user = UserRepository
                       .GetById(request.UserId);

            if (user is null)
            {
                result.AddError($"User with id {request.UserId} was not found", HttpStatusCode.NotFound);
                return(result);
            }

            user.BalanceValue -= Math.Round(request.Value, 2);

            user.HistoricalBalances ??= new List <HistoricalBalance>();

            user.HistoricalBalances.Add(new HistoricalBalance()
            {
                BalanceValue = user.BalanceValue,
                Id           = Guid.NewGuid().ToString(),
                CreatedAt    = DateTime.UtcNow
            });

            UserRepository.Update(user);

            var expense = new Expense()
            {
                Id        = Guid.NewGuid().ToString(),
                CreatedAt = DateTime.UtcNow,
                Name      = request.Name,
                Value     = Math.Round(request.Value, 2),
                User      = user
            };

            ExpenseRepository.Add(expense);
            ExpenseRepository.SaveChanges();

            result.SetSingleItem(Mapper.Map <ExpenseDto>(expense));
            result.StatusCode = HttpStatusCode.OK;

            return(result);
        }
Exemplo n.º 18
0
        public override IActionResult Post([FromBody] Expense model)
        {
            try
            {
                var activeEntity = model as ICommonData;
                if (activeEntity != null)
                {
                    activeEntity.Active = true;
                    model = activeEntity as Expense;
                }
                var result = _repo.Add(model);

                return(Ok(result));
            }

            catch (Exception ex)
            {
                return(Ok(new { status = -1, message = ex.Message }));
            }
        }
Exemplo n.º 19
0
        public async Task <Expense> InsertAsync(int categoryId, InsertUpdateExpenseCommand command)
        {
            var category = await _categoryRepository.GetAsync(categoryId);

            if (category == null)
            {
                throw new EntityNotFoundException("Category");
            }

            if (category.Archived)
            {
                throw new BusinessException($"Category {category.Name} is already archived");
            }

            var customer = await _customerRepository.GetAsync(command.CustomerId);

            if (customer == null)
            {
                throw new EntityNotFoundException("Customer");
            }

            if (customer.Archived)
            {
                throw new BusinessException($"Customer {customer.CommercialName} is already archived");
            }

            var expense = new Expense
            {
                Amount          = command.Amount,
                AccrualDate     = command.AccrualDate,
                TransactionDate = command.TransactionDate,
                Category        = category,
                Customer        = customer,
                Description     = command.Description,
            };

            _expenseRepository.Add(expense);
            await _expenseRepository.SaveChangesAsync();

            return(expense);
        }
Exemplo n.º 20
0
        public SaveResultModel <Expense> CreateExpense(Expense model)
        {
            if (!_expenseValidator.Validate(model, out var errorMessages))
            {
                return(new SaveResultModel <Expense>
                {
                    Success = false,
                    Model = model,
                    ErrorMessages = errorMessages
                });
            }

            var alreadyExists = _expenseRepository.Get(g => g.Description == model.Description &&
                                                       g.CurrentAmount == model.CurrentAmount &&
                                                       g.InitialAmount == model.InitialAmount &&
                                                       g.Payer == model.Payer) != null;

            if (alreadyExists)
            {
                return(new SaveResultModel <Expense>
                {
                    Success = false,
                    Model = model,
                    ErrorMessages = new List <string> {
                        "A expense with the same description, amount and payer already exists."
                    }
                });
            }

            _expenseRepository.Add(model);
            _unitOfWork.Commit();

            return(new SaveResultModel <Expense>
            {
                Success = true,
                Model = model,
                ErrorMessages = errorMessages
            });
        }
Exemplo n.º 21
0
        public Task <Guid> CreateExpense(ExpenseObject obj)
        {
            return(Task.Run(() =>
            {
                try
                {
                    if (obj.Id == Guid.Empty)
                    {
                        var dataObj = new MapperConfiguration(ap =>
                        {
                            ap.CreateMap <ExpenseObject, Expense>();
                        });

                        IMapper iMapper = dataObj.CreateMapper();

                        var source = new Expense();

                        source.Id = IdentityGenerator.NewSequentialGuid();
                        source.Amount = obj.Amount;
                        source.Date = obj.Date;
                        source.Details = obj.Details;

                        expenseRepo.Add(source);
                        expenseRepo.UnitofWork.Commit();

                        return source.Id;
                    }

                    else
                    {
                        throw new InvalidOperationException();
                    }
                }
                catch (Exception)
                {
                    throw;
                }
            }));
        }
        public ICommandResult Execute(CreateOrUpdateExpenseCommand command)
        {
            var expense = new Expense
            {
                ExpenseId   = command.ExpenseId,
                CategoryId  = command.CategoryId,
                Amount      = command.Amount,
                Date        = command.Date,
                Transaction = command.Transaction
            };

            if (expense.ExpenseId == 0)
            {
                expenseRepository.Add(expense);
            }
            else
            {
                expenseRepository.Update(expense);
            }
            unitOfWork.Commit();
            return(new CommandResult(true));
        }
Exemplo n.º 23
0
 public async Task <ActionResult <Expense> > PostExpense(Expense expense)
 {
     return(await _repository.Add(expense));
 }
Exemplo n.º 24
0
 public ActionResult <bool> Post([FromBody] Expense expense)
 {
     logger.Info($"Creating Expense {expense}");
     _expenseRepository.Add(expense);
     return(true);
 }