public ActionResult Create(PlayPeriodDto request) { var currentUserId = HttpContext.User.Identity.GetUserId(); ApplicationUser user = HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>().FindById(currentUserId); mTicketCommand.Create(request, user.Email); return Json("success"); }
public void Create(PlayPeriodDto request, string userEmail) { using (var context = mDbContextFactory.CreateContext()) { var currentPlayPeriod = context.Set<PlayPeriod>().FirstOrDefault(x => x.Id == request.Id); if (currentPlayPeriod == null) { throw new ApplicationException("Период не найден"); } currentPlayPeriod.TicketsCapacity--; var ticket = new Ticket { Id = Guid.NewGuid(), UserEmail = userEmail }; currentPlayPeriod.Tickets.Add(ticket); context.SaveChanges(); } }