public IActionResult EventRequest(string eventId) { int? ID = HttpContext.Session.GetInt32("userid"); Vendor user = _context.users .OfType <Vendor>() .Where(vendor => vendor.UserId == ID) .FirstOrDefault(); if (user == null) { return(Redirect("/fail")); } if (Int32.TryParse(eventId, out int id)) { Event thisEvent = _context.events .Include(eve => eve.EventVendors) .FirstOrDefault(ev => ev.EventId == id); if (thisEvent == null) { return(Redirect("/fail")); } VendorToEvent ifExistsCheck = thisEvent.EventVendors .Find(ev => ev.Vendor == user); if (ifExistsCheck != null) { return(Redirect("/fail")); } VendorToEvent thisRequest = new VendorToEvent(user, thisEvent); _context.eventvendors.Add(thisRequest); thisEvent.EventVendors.Add(thisRequest); user.Events.Add(thisRequest); _context.SaveChanges(); } return(Redirect("/event-detail/" + eventId)); }
public IActionResult DenyVendor(string EventId, string VendorId) { int? ID = HttpContext.Session.GetInt32("userid"); Broker user = _context.users .OfType <Broker>() .Where(use => use.UserId == ID) .FirstOrDefault(); if (user == null) { return(Redirect("/fail")); } if (Int32.TryParse(EventId, out int id)) { Event eventToConfirm = _context.events .Include(eve => eve.EventVendors) .ThenInclude(ve => ve.Vendor) .FirstOrDefault(eve => eve.EventId == id); if (Int32.TryParse(VendorId, out int vid)) { VendorToEvent Request = eventToConfirm.EventVendors.Find(re => re.Vendor.UserId == vid); if (Request == null) { return(Redirect("/fail")); } if (Request.Event.Broker == user) { Request.RequestStatus = "Denied"; _context.SaveChanges(); } } } return(Redirect("/event-detail/" + EventId)); }