/// <summary> /// Pay subscription /// </summary> /// <param name="id">AdherentStolon id</param> /// <returns></returns> public IActionResult PaySubscription(Guid id) { if (!Authorized(Role.Volunteer)) { return(Unauthorized()); } //Adherent stolon AdherentStolon adherentStolon = _context.AdherentStolons.Include(x => x.Stolon).Include(x => x.Adherent).First(x => x.Id == id); adherentStolon.SubscriptionPaid = true; _context.AdherentStolons.Update(adherentStolon); //Transaction Transaction transaction = new Transaction(); transaction = new AdherentTransaction() { Adherent = adherentStolon.Adherent }; //Update transaction.Amount = Configurations.GetSubscriptionAmount(adherentStolon); //Add a transaction transaction.Stolon = adherentStolon.Stolon; transaction.AddedAutomaticly = true; transaction.Date = DateTime.Now; transaction.Type = Transaction.TransactionType.Inbound; transaction.Category = Transaction.TransactionCategory.Subscription; transaction.Description = "Paiement de la cotisation de l'adhérant " + (adherentStolon.IsProducer?"producteur":"") + " : " + adherentStolon.Adherent.Name + " " + adherentStolon.Adherent.Surname; _context.Transactions.Add(transaction); //Save _context.SaveChanges(); return(RedirectToAction("Index")); }
public async Task <IActionResult> Create(TransactionViewModel transactionVm) { if (ModelState.IsValid) { AdherentTransaction adherentTransaction = new AdherentTransaction(GetActiveAdherentStolon().Adherent, GetCurrentStolon(), transactionVm.Transaction.Type, transactionVm.Transaction.Category, transactionVm.Transaction.Amount, transactionVm.Transaction.Description, false); _context.Add(adherentTransaction); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(transactionVm)); }