public static bool ValidateRequest(UpdateEventDto updateEventRequest) { var hasErrors = false; var errors = new StringBuilder(); if (string.IsNullOrEmpty(updateEventRequest?.Id)) { hasErrors = true; errors.AppendLine($"{nameof(updateEventRequest.Id)} is required."); } if (string.IsNullOrEmpty(updateEventRequest?.Title)) { hasErrors = true; errors.AppendLine($"{nameof(updateEventRequest.Title)} is required."); } if (updateEventRequest?.StartTime >= updateEventRequest?.EndTime) { hasErrors = true; errors.AppendLine("Invalid event start and end times."); } if (hasErrors) { throw new ValidationException(errors.ToString()); } return(true); }
public void Update(UpdateEventDto eventDto) { Guid Id = new Guid(eventDto.Id); Event eventToUpdate = _repository.GetByFilter <Event>(p => p.Id == Id); if (eventToUpdate == null) { return; } if (eventDto.Title != null) { eventToUpdate.Title = eventDto.Title; } if (eventDto.Description != null) { eventToUpdate.Description = eventDto.Description; } if (eventDto.StartDate != null) { eventToUpdate.StartDate = eventDto.StartDate; } if (eventDto.EndDate != null) { eventToUpdate.EndDate = eventDto.EndDate; } if (eventDto.Department != null) { eventToUpdate.Department = eventDto.Department; } _repository.Update(eventToUpdate); _repository.Save(); }
public async Task <ServiceResponse <GetEventDto> > UpdateEvent(UpdateEventDto updatedEvent) { ServiceResponse <GetEventDto> serviceResponse = new ServiceResponse <GetEventDto>(); try { webApi.Models.Event events = await _context.Events.Include(c => c.Tournament.user).FirstOrDefaultAsync(c => c.eventID == updatedEvent.eventID); if (events.Tournament.user.Id == GetUserId()) { events.eventName = updatedEvent.eventName; events.Tournament = updatedEvent.Tournament; events.eventNumber = updatedEvent.eventNumber; events.eventDateTime = updatedEvent.eventDateTime; events.eventEndDateTime = updatedEvent.eventEndDateTime; _context.Events.Update(events); await _context.SaveChangesAsync(); serviceResponse.Data = _mapper.Map <GetEventDto>(events); } else { serviceResponse.Success = false; serviceResponse.Message = "Event not found."; } } catch (Exception ex) { serviceResponse.Success = false; serviceResponse.Message = ex.Message; } return(serviceResponse); }
public async Task <IActionResult> UpdateEventsAsync(UpdateEventDto updateEventDto) { var result = await _eventService.GetListAsync(updateEventDto).ConfigureAwait(true); return(result == null ? (IActionResult)NotFound($"Could not add {typeof(EventDto).Name}") : Ok(result)); }
public async Task <IActionResult> UpdateEvent(int eventId, UpdateEventDto eventDto) { eventDto.EventId = eventId; await _service.UpdateEvent(eventDto); return(NoContent()); }
public void UpdateEventDtoModelTests() { UpdateEventDto ueDto = new UpdateEventDto { TargetValidator = "0x00000" }; ueDto.TargetValidator.Should().Be("0x00000"); }
public async Task UpdateEventAsync(Guid eventId, Guid userId, UpdateEventDto updateEventDto) { await TryUpdateAsync(eventId, userId, @event => { @event.Title = updateEventDto.Title; @event.Description = updateEventDto.Description; @event.StartsAt = updateEventDto.StartsAt; @event.EndsAt = updateEventDto.EndsAt; }); }
public IActionResult UpdateEvent([FromBody] UpdateEventDto updateEventDto) { if (updateEventDto.Id != 0 && !ModelState.IsValid) { return(BadRequest()); } return(Ok(_eventService.UpdateEvent(updateEventDto))); }
public IActionResult UpdateEvent([FromBody] UpdateEventDto eventDto) { if (!ModelState.IsValid) { return(BadRequest()); } _eventServices.UpdateEvent(eventDto); return(Ok()); }
public bool UpdateEvent(int userId, UpdateEventDto eventObj) { if (eventObj.AssignerId == userId) { var updatedEvent = _mapper.Map <Event>(eventObj); _db.Event.Update(updatedEvent); return(Save()); } return(false); }
public async Task <IActionResult> UpdateEvent(UpdateEventDto updatedEvent) { ServiceResponse <GetEventDto> response = await _eventService.UpdateEvent(updatedEvent); if (response.Data == null) { return(NotFound(response)); } return(Ok(response)); }
public EventDto UpdateEvent(UpdateEventDto updateEventDto) { var @event = _iMapper.Map <Event>(updateEventDto); _context.Events.Update(@event); _context.SaveChanges(); var eventDto = _iMapper.Map <EventDto>(@event); return(eventDto); }
public async Task <List <SendEventDto> > GetListAsync(UpdateEventDto updateEventDto) { var events = await _eventRepository.GetListAsync(x => updateEventDto.ExternalId.Contains(x.ExternalId)).ConfigureAwait(false); foreach (var @event in events) { @event.EventDates = await _eventDateRepository.GetListAsync(x => x.EventId == @event.Id).ConfigureAwait(false); } return(Mapper.Map(events).ToANew <List <SendEventDto> >().ToList()); }
public ActionResult Update([FromBody] UpdateEventDto dto, [FromRoute] int id) { var isUpdated = _eventService.Update(id, dto); if (isUpdated) { return(NotFound()); } return(Ok()); }
public async Task <IActionResult> Update(Guid id, UpdateEventDto updateEvent) { updateEvent.Id = id; var result = await _unitOfWork.EventService.Update(updateEvent, UserId); if (!result.Success) { return(result.ApiResult); } return(NoContent()); }
public UpdateEvent( UpdateEventDto updateEventRequest, CloudTable eventsTable, string loginUserEmail, string loginUserId, ILogger logger) { _updateEventRequest = updateEventRequest; _loginUserEmail = loginUserEmail; _loginUserId = loginUserId; _eventsTable = eventsTable; _logger = logger; }
public async Task <IActionResult> Put([FromBody] UpdateEventDto updateEventDto) { var user = await _userService.GetById(int.Parse(User.FindFirstValue(ClaimTypes.NameIdentifier))); if (updateEventDto.PlannerId != user.PlannerId) { return(BadRequest()); } await _eventService.Update(updateEventDto); return(Ok()); }
public void UpdateEvent(UpdateEventDto updateEventDto) { Event @event = new Event() { Id = updateEventDto.Id, Name = updateEventDto.Name, StartTime = updateEventDto.StartTime, EndTime = updateEventDto.EndTime, ParticipantsNumber = updateEventDto.ParticipantsNumber }; _repository.Update(@event); }
public void Update(UpdateEventDto updateEventDto) { var _event = _medicineRemainderContext.Events.SingleOrDefault(x => x.Id == updateEventDto.Id); if (_event != null) { _event.Message = updateEventDto.Message; _event.Name = updateEventDto.Name; _event.RemaindDate = updateEventDto.RemaindDate; } else { throw new Exception($"Couldn't find the event with {updateEventDto.Id} id"); } }
public IActionResult UpdateEvent(int userId, [FromBody] UpdateEventDto eventObj) { if (eventObj == null || userId != eventObj.AssignerId) { ModelState.AddModelError("", "Unauthorized!"); return(StatusCode(404, ModelState)); } if (!_evRepo.UpdateEvent(userId, eventObj)) { ModelState.AddModelError("", $"Something went wrong when updating the event"); return(StatusCode(500, ModelState)); } return(Ok(eventObj)); }
public bool Update(int id, UpdateEventDto dto) { var events = _dbContext .Events .FirstOrDefault(e => e.Id == id); if (events is null) { return(false); } events.Name = dto.Name; events.Description = dto.Description; events.Date = dto.Date; _dbContext.SaveChanges(); return(true); }
public async Task Update(int id, UpdateEventDto updateEventData) { if (updateEventData == null) { throw new ArgumentNullException(nameof(updateEventData)); } var eventToUpdate = await _repository.GetById(id); if (eventToUpdate == null) { throw new InvalidOperationException(); } _mapper.Map(updateEventData, eventToUpdate); await _repository.Update(eventToUpdate); await _eventService.Update(id, updateEventData); }
public async Task UpdateEvent(UpdateEventDto updateEventDto) { var eventEntity = await _context .Events .GetActiveEventById(updateEventDto.EventId) .FirstOrDefaultAsync(); if (eventEntity == null) { throw new ItemNotFoundException(); } eventEntity.OrganizerId = updateEventDto.OrganizerId; eventEntity.Title = updateEventDto.Title; eventEntity.Description = updateEventDto.Description; eventEntity.Location = updateEventDto.Location; eventEntity.StartTime = updateEventDto.StartTime; eventEntity.EndTime = updateEventDto.EndTime; _context.Save(); }
public async Task <IActionResult> PutEvent(ulong id, UpdateEventDto updateEventDto) { if (!IsAdmin() && updateEventDto.Creator != Convert.ToUInt64(UserId)) { return(Unauthorized("You can not update an event for another user.")); } try { EventDto eventDto = await _business.Update <EventDto, UpdateEventDto>(id, updateEventDto, (eventEntity => IsAdmin() || eventEntity.Creator == Convert.ToUInt64(UserId))); return(Ok(eventDto)); } catch (ArgumentNullException) { return(BadRequest($"An event with id \"{id}\" was not found.")); } catch (ConditionFailedException) { return(Unauthorized("You can not update an event for another user.")); } }
public void EditEvent(UpdateEventDto updateEventDto) { _eventRespository.Update(updateEventDto); }
public async Task <IActionResult> UpdateEventAsync([FromRoute] Guid eventId, [FromBody] UpdateEventDto updateEventDto) { await _eventOrganizerService.UpdateEventAsync(eventId, UserId, updateEventDto); return(NoContent()); }
public async Task <Result> Update(UpdateEventDto updateEventDto, Guid userId) { var category = await Context.Categories.FirstOrDefaultAsync(c => c.Id == updateEventDto.CategoryId); if (category == null) { return(Result.Failed(new NotFoundObjectResult(new ApiMessage { Message = ResponseMessage.CategoryNotFound }))); } var host = await Context.Hosts.FirstOrDefaultAsync(c => c.Id == updateEventDto.HostId); if (host == null) { return(Result.Failed(new NotFoundObjectResult(new ApiMessage { Message = ResponseMessage.HostNotFound }))); } var eventDetail = await FirstOrDefaultAsync(x => x.Id == updateEventDto.Id && !x.IsDeleted , e => e.Category, e => e.Host, e => e.UserInEvents.Select(ur => ur.User), e => e.EventGallery.Select(gallery => gallery.User), e => e.EventSchedule, e => e.Comment.Select(c => c.ParentComment), e => e.Comment.Select(c => c.Children)); if (eventDetail is null) { return(Result.Failed(new NotFoundObjectResult(new ApiMessage { Message = ResponseMessage.EventNotFound }))); } if (eventDetail.UserInEvents != null && eventDetail.UserInEvents.Any()) { Context.RemoveRange(eventDetail.UserInEvents); } if (eventDetail.EventGallery != null && eventDetail.EventGallery.Any()) { Context.RemoveRange(eventDetail.EventGallery); } eventDetail.UserInEvents = updateEventDto.Users? .Select(uId => new UserInEvent { Guid = Guid.NewGuid(), EventId = eventDetail.Id, UserId = uId }) .ToList(); eventDetail.EventGallery = updateEventDto.EventGallery? .Select(gallery => new EventGallery { Id = Guid.NewGuid(), EventId = eventDetail.Id, UserId = userId, Image = gallery }) .ToList(); if (eventDetail.UserInEvents != null && eventDetail.UserInEvents.Any()) { Context.AddRange(eventDetail.UserInEvents); } if (eventDetail.EventGallery != null && eventDetail.EventGallery.Any()) { Context.AddRange(eventDetail.EventGallery); } _mapper.Map(updateEventDto, eventDetail); var dateFromHour = updateEventDto.EventSchedule.StartHour; var dateToHour = updateEventDto.EventSchedule.EndHour; TimeSpan fromHour; TimeSpan toHour; if (TimeSpan.TryParse(dateFromHour, out fromHour)) { if (TimeSpan.TryParse(dateToHour, out toHour)) { eventDetail.EventSchedule.StartHour = fromHour; eventDetail.EventSchedule.EndHour = toHour; } } eventDetail.Category = category; eventDetail.Host = host; await Context.SaveChangesAsync(); return(Result.SuccessFull()); }
public IActionResult Update([FromBody] UpdateEventDto updateEventDto) { _eventService.EditEvent(updateEventDto); return(Ok()); }
public async Task <IActionResult> Put(int id, [FromBody] UpdateEventDto updateEventDto) { await _eventService.Update(id, updateEventDto); return(NoContent()); }
public IActionResult Update([FromBody] UpdateEventDto eventDto) { _eventLogic.Update(eventDto); return(NoContent()); }