public async Task <IActionResult> GetBusiness(int id) { IActionResult result = null; var addresses = await _eventServices .GetAll(); await _businessServices.GetAll(); var oneBusiness = await _businessServices .Get(id); if (oneBusiness == null) { result = NotFound(); } else { var model = await _businessServices.Get(oneBusiness.Id); model.Address = await _addressServices.Get(oneBusiness.Address.Id); model.Events = await _context.Events.Where(x => x.Id == oneBusiness.Id).ToListAsync(); // model.Events = await _eventServices.GetAll(); await _eventTypeServices.GetAll(); // var links = await _context.EventApplicationUsers // .Where(x => x.EventId == oneEvent.Id) // .ToListAsync(); result = View("Business", model); } return(result); }
public async Task <IActionResult> CreateEvent(CreateEventView event1) { var user = await _userManager.GetUserAsync(User); event1.Event.Address = await _addressServices.Get(event1.Event.Address.Id); event1.Event.Business = await _businessServices.Get(event1.Event.Business.Id); event1.Event.EventType = await _context.EventTypes.FindAsync(event1.Event.EventType.Id); event1.Event.ApplicationUser = user; //[Bind("Id,AddressId,BusinessId,ApplicationUserId,StartDate,EndDate,PriceToPayToParticipate,Title,EventTypeId")] // if (ModelState.IsValid) // { _context.Events.Add(event1.Event); await _context.SaveChangesAsync(); var link = new EventApplicationUser { ApplicationUserId = user.Id, EventId = event1.Event.Id }; var eventUser = await _context.EventApplicationUsers .AddAsync(link); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); // }else { // return RedirectToAction(nameof(CreateEvent)); }