public IActionResult AddOrUpdate(int?id) { Event = new EventInfoViewModel(); Event.AllEventTypes = _eventService.GetAllEventTypes(); if (id == null) { // Add var creationDate = DateTime.Now; Event.DateAdded = creationDate; Event.DateHappens = creationDate; Event.EventType = EventTypeId.Conference.ToString("G"); } else { // Edit var eventToEdit = _eventService.GetById(id.Value); if (eventToEdit == null) { return(NotFound()); } Event.Id = eventToEdit.Id; Event.DateAdded = eventToEdit.DateAdded; Event.DateHappens = eventToEdit.DateHappens; Event.Description = eventToEdit.Description; Event.EventType = eventToEdit.EventTypeId.ToString("G"); Event.Location = eventToEdit.Location; Event.MaxGuestsCount = eventToEdit.MaxGuestsCount; Event.Name = eventToEdit.Name; } return(View(Event)); }
public EventDetailPage(EventInfoViewModel viewModel) { InitializeComponent(); _viewModel = viewModel; BindingContext = _viewModel; }
public async Task <IActionResult> Insert(string moniker, [FromBody] EventInfoViewModel vm) { try { if (moniker != vm.Moniker) { return(BadRequest("Wrong Event with Moniker")); } var info = _repo.GetEventInfo(vm.Moniker); if (info != null) { return(BadRequest("Cannot add duplicate moniker")); } else { info = _mapper.Map <EventInfo>(vm); info.Name = $"Event Name for {vm.Moniker}"; info.Location = new EventLocation(); } _repo.AddOrUpdate(info); await _repo.SaveChangesAsync(); return(Created($"/api/events/{info.Moniker}", _mapper.Map <EventInfoViewModel>(info))); } catch (Exception ex) { _logger.LogError("Failed to upsert EventInfo. {0}", ex); } return(BadRequest("Failed to save new event.")); }
public async Task <IActionResult> Update(string moniker, [FromBody] EventInfoViewModel vm) { try { if (ModelState.IsValid) { if (moniker != vm.Moniker) { return(BadRequest("Wrong Event with Moniker")); } var info = _repo.GetEventInfo(moniker); if (info == null) { return(BadRequest("Cannot add update new event")); } else { _mapper.Map(vm, info); } _repo.AddOrUpdate(info); await _repo.SaveChangesAsync(); return(Ok(_mapper.Map <EventInfoViewModel>(info))); } } catch (Exception ex) { _logger.LogError("Failed to upsert EventInfo. {0}", ex); } return(BadRequest("Failed to update event.")); }
public async Task <IActionResult> Upsert([FromBody] EventInfoViewModel vm) { try { var info = _repo.GetEventInfo(vm.Moniker); if (info == null) { info = Mapper.Map <EventInfo>(vm); } else { Mapper.Map(vm, info); } _repo.AddOrUpdate(info); await _repo.SaveChangesAsync(); return(Ok(Mapper.Map <EventInfoViewModel>(info))); } catch (Exception ex) { _logger.LogError("Failed to upsert EventInfo. {0}", ex); } return(BadRequest("Failed to save new event.")); }
public IActionResult ManageGuests(int?id) { Event = new EventInfoViewModel(); Event.AllEventTypes = _eventService.GetAllEventTypes(); if (id == null) { return(NotFound()); } else { // Edit var eventToEdit = _eventService.GetById(id.Value); if (eventToEdit == null) { return(NotFound()); } Event.Id = eventToEdit.Id; Event.DateAdded = eventToEdit.DateAdded; Event.DateHappens = eventToEdit.DateHappens; Event.Description = eventToEdit.Description; Event.EventType = eventToEdit.EventTypeId.ToString("G"); Event.Location = eventToEdit.Location; Event.MaxGuestsCount = eventToEdit.MaxGuestsCount; Event.Name = eventToEdit.Name; Event.ListOfGuests = eventToEdit.ListOfGuests.Select(g => new GuestInfoViewModel { Id = g.Id, FirstName = g.FirstName, LastName = g.LastName, Patronymic = g.Patronymic, Email = g.Email, AssociatedEvent = Event, Comment = g.Comment, }); } return(View(Event)); }