public async Task <ActionResult <EventUpdateDTO> > Put(int EventId, EventUpdateDTO eventUpdateDto) { try { var oldEvent = await _eventRepository.GetEventByIdAsync(EventId); if (oldEvent == null) { return(NotFound($"Could not find event with id of {EventId}")); } _mapper.Map(eventUpdateDto, oldEvent); if (await _eventRepository.SaveChangeAsync()) { return(_mapper.Map <EventUpdateDTO>(oldEvent)); } } catch (Exception) { /* * return this.StatusCode(StatusCodes.Status500InternalServerError, "Database Failure"); */ } return(BadRequest()); }
public async Task <bool> EditEvent(EventUpdateDTO dto) { var rao = _mapper.Map <EventUpdateRAO>(dto); if (await _repository.EditEvent(rao)) { return(true); } throw new NotImplementedException(); }
public ActionResult UpdateEvent(int id, EventUpdateDTO eventUpdateDto) { var eventFromRepo = _repository.Events.GetById(id, true); if (eventFromRepo == null) { return(NotFound()); } _mapper.Map(eventUpdateDto, eventFromRepo); _repository.Events.UpdateEvent(eventFromRepo); _repository.Save(); return(NoContent()); }
public async Task <IActionResult> Put([FromRoute] string id, [FromBody] EventUpdateDTO dto) { EventFindDTO updatedEvent = await this.EventService.Update( this.User.GetEstablishmentId(), new ObjectId(id), dto ); if (updatedEvent == null) { return(NotFound()); } return(Ok(updatedEvent)); }
public ActionResult UpdateEvent(int id, EventUpdateDTO eventUpdateDTO) { var eve = _eventService.GetEventById(id); if (eve == null) { return(NotFound()); } _mapper.Map(eventUpdateDTO, eve); _eventService.UpdateEvent(eve); _eventService.SaveChanges(); return(NoContent()); }
/// <summary> /// Update existing event. /// </summary> /// <param name="establishmentId"></param> /// <param name="id"></param> /// <param name="dto"></param> /// <returns></returns> public async Task <EventFindDTO> Update(ObjectId establishmentId, ObjectId id, EventUpdateDTO dto) { Event updateEvent = this.MongoRepository.FindById <Event>(id); if (updateEvent == null || updateEvent.EstablishmentId != establishmentId) { return(null); } Establishment establishment = this.MongoRepository.FindById <Establishment>(establishmentId); updateEvent.Name = dto.Name; updateEvent.Description = dto.Description; updateEvent.SetDate(dto.StartDate, dto.EndDate); if (!string.IsNullOrEmpty(dto.Image)) { await this.ImageService.DeleteImage(updateEvent.Image); await this.ImageService.DeleteImage(updateEvent.ImageThumbnail); UploadImageModel uploadedImage = await this.ImageService.UploadImage( EventService.EventsContainer, dto.Image); updateEvent.Image = uploadedImage.Image; updateEvent.ImageThumbnail = uploadedImage.Thumbnail; } updateEvent.Genres.Clear(); foreach (GenreEnum genre in dto.Genres) { updateEvent.AddGenre(genre); } updateEvent.EstablishmentLocation = dto.Location == null; updateEvent.Location = dto.Location != null ? new Location( dto.Location.Street, dto.Location.Number, dto.Location.State, dto.Location.Country, dto.Location.City, new GeoJson2DGeographicCoordinates( dto.Location.Longitude, dto.Location.Latitude ) ) : establishment.Location; this.MongoRepository.Update(updateEvent); return(this.Find(id)); }