Exemplo n.º 1
0
        public async Task <AddPayslipResponse> AddUserPayslipAsync(AddPayslipRequest model)
        {
            var repository = UnitOfWork.AsyncRepository <User>();
            var user       = await repository.GetAsync(_ => _.Id == model.UserId);

            if (user != null)
            {
                var payslip = user.AddPayslip(model.Date.Value
                                              , model.WorkingDays.Value
                                              , model.Bonus
                                              , model.IsPaid.Value);

                await repository.UpdateAsync(user);

                await UnitOfWork.SaveChangesAsync();

                return(new AddPayslipResponse()
                {
                    UserId = user.Id,
                    TotalSalary = payslip.TotalSalary
                });
            }

            throw new Exception("User not found.");
        }
Exemplo n.º 2
0
        public async Task <IActionResult> AddPayslip([FromBody] AddPayslipRequest request)
        {
            var users = await _service.AddUserPayslipAsync(request);

            return(Ok(users));
        }