public async Task <Payment> CreateNewPayment(CustomPaymentDetailsDTO customPaymentDetails) { var flat = await _context.Flats.Include(p => p.Payments).Include(p => p.Residents).FirstOrDefaultAsync(p => p.Id == customPaymentDetails.FlatId); var payment = new Payment() { Month = customPaymentDetails.Period.Month, Year = customPaymentDetails.Period.Year, Name = customPaymentDetails.Name, PaymentStatus = PaymentStatus.WaitingForUser, PaymentType = PaymentType.CUSTOM, PaymentDeadline = customPaymentDetails.Deadline, Value = customPaymentDetails.Value, Description = customPaymentDetails.Description }; flat.Payments.Add(payment); await _context.SaveChangesAsync(); return(payment); }
public async Task <IActionResult> CreateNewCustomPayment(CustomPaymentDetailsDTO customPaymentDetails) { var user = await _userRepository.GetUserById(customPaymentDetails.UserId); var access = await _authRepository.HasAdministrationRights(customPaymentDetails.UserId); if (!access) { return(BadRequest("User has no proper priviliges")); } var payment = await _repo.CreateNewPayment(customPaymentDetails); var messageSubject = "Stworzono polecenie płatności"; var messageContent = $"Płatnośc została stworzona przez użytkownika: {user.FirstName} {user.LastName}.\n" + $"W razie zastrzeżeń skontaktuj się z pracownikiem administracji. \n\n" + $"Treść maila wygenerowano automatycznie. Nie odpowiadaj na tego maila."; _mailService.SendMail(messageSubject, messageContent, "", "Home Community App"); return(Ok()); }