Пример #1
0
        public async Task <IActionResult> createEvent([FromBody] inputEvent events)
        {
            try
            {
                // checking event exists
                var eventExist = dbContext.Events.SingleOrDefault(a => a.EventName == events.EventName);


                if (eventExist != null)
                {
                    return(BadRequest("Event with same name already exists"));
                }
                // create an object of events type
                var newEvent = new Events
                {
                    EventName   = events.EventName,
                    DateTime    = events.DateTime,
                    Time        = events.Time,
                    Description = events.Description,
                    EventTypeId = dbContext.EventTypes.SingleOrDefault(a => a.EventTypeName == events.EventType).EventTypeId, //get event by id
                    HostId      = events.HostId,
                    VenueId     = dbContext.Venues.SingleOrDefault(a => a.VenueName == events.Venue).VenueId                  //get venue by id
                };
                // insert into database
                dbContext.Events.Add(newEvent);
                await dbContext.SaveChangesAsync();

                return(Ok(new { message = "Event created successfully" }));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
Пример #2
0
 /// <summary>
 /// NEW
 /// Links the input key to the method
 /// </summary>
 /// <param name="input">ConsoleKey that triggers</param>
 /// <param name="e">Method that gets invoked by the input</param>
 public static void AddInput(ConsoleKey input, inputEvent e)
 {
     events.Add(input, e);
 }