public IActionResult AddEvent([FromBody] LocalEventsViewModel eventViewModel) { try { LocalEvent newEvent = Mapper.Map <LocalEventsViewModel, LocalEvent>(eventViewModel); newEvent.EventId = null; newEvent.UserId = IdentityHelper.GetUserId(HttpContext); newEvent.IsApproved = 0; newEvent.Expired = 0; newEvent.CreationDate = DateTime.Now; newEvent.LastUpdate = DateTime.Now; _localEventsRepository.addEvent(newEvent); string content = "A new event listing has been added\n" + "\nID: " + newEvent.EventId + "\nEvent name: " + newEvent.EventName + "\n\nPlease go to https://capstone1.azurewebsites.net/admin to approve this event listing"; string subject = "New event listing"; _emailService.SendToAdmins(subject, content); return(Ok()); } catch (Exception ex) { return(BadRequest()); } }
public IActionResult EditEvent([FromBody] LocalEventsViewModel localEventViewModel) { try { if (localEventViewModel.EventId.HasValue) { LocalEvent localEvent = _localEventsRepository.GetEventById(localEventViewModel.EventId.Value); if (localEvent.UserId == IdentityHelper.GetUserId(HttpContext)) { _localEventsRepository.editEvent(localEventViewModel); return(Ok()); } else { return(Unauthorized()); } } else { return(BadRequest()); } } catch (Exception ex) { return(BadRequest()); } }
public void editEvent(LocalEventsViewModel newEvent) { LocalEvent oldEvent = GetEventById(newEvent.EventId.Value); _context.LocalEvents.Attach(oldEvent); oldEvent.LastUpdate = DateTime.Now; oldEvent.EventName = newEvent.EventName; oldEvent.hostedBy = newEvent.HostedBy; oldEvent.Contact = newEvent.Contact; oldEvent.Website = newEvent.Website; oldEvent.StartDate = newEvent.StartDate; oldEvent.Duration = newEvent.Duration; oldEvent.Recurring = newEvent.Recurring; oldEvent.EventDescription = newEvent.EventDescription; oldEvent.EventType = newEvent.EventType; oldEvent.EventLocation = newEvent.EventLocation; oldEvent.ImageURL = newEvent.ImageURL; _context.SaveChanges(); }