public bool Update(EventForUpdateDto eventForUpdate)
        {
            try
            {
                var eventDto = GetById(eventForUpdate.id);

                if (eventDto == null)
                {
                    return(false);
                }

                Event DataEntity = _mapper.Map <Event>(eventDto);

                _mapper.Map(eventForUpdate, DataEntity);

                IEnumerable <EventGenreDto> eventGenres = _eventGenreLogic.GetByEvent(DataEntity.id);
                foreach (EventGenreDto eventGenre in eventGenres)
                {
                    _eventGenreLogic.Delete(eventGenre.event_id, eventGenre.genre_id);
                }

                _eventRepository.Update(DataEntity);
                _eventRepository.Save();

                _logger.LogError($"Updated Event with id: {DataEntity.id}");

                return(true);
            }
            catch (Exception ex)
            {
                _logger.LogError($"Something went wrong inside UpdateEvent action: {ex.Message}");
                throw new Exception();
            }
        }
Example #2
0
        public IActionResult UpdateEvent(int id,
                                         [FromBody] EventForUpdateDto eventDto)
        {
            if (eventDto == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var eventEntity = _registrationRepository.GetEvent(id);

            if (eventEntity == null)
            {
                return(NotFound());
            }

            Mapper.Map(eventDto, eventEntity);

            if (!_registrationRepository.Save())
            {
                return(StatusCode(500, "A problem happened while handling your request."));
            }

            return(NoContent());
        }
Example #3
0
        public IActionResult UpdateEvent([FromBody] EventForUpdateDto @event)
        {
            try
            {
                if (@event == null)
                {
                    _logger.LogError("Event object sent from client is null.");
                    return(BadRequest("Event object is null"));
                }

                if (!ModelState.IsValid)
                {
                    _logger.LogError("Invalid Event object sent from client.");
                    return(BadRequest("Invalid model object"));
                }

                bool succes = _eventLogic.Update(@event);

                if (!succes)
                {
                    return(NotFound());
                }

                return(Ok(true));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, "Internal server error"));
            }
        }
Example #4
0
        public async Task <EventForUpdateDto> UpdateEvent(int id, EventForUpdateDto ev)
        {
            var dbEvent = await _context.Events.FindAsync(id);

            dbEvent.Title       = ev.Title;
            dbEvent.Location    = ev.Location;
            dbEvent.Description = ev.Description;
            dbEvent.StartDate   = new DateTime(ev.StartDate.Year, ev.StartDate.Month,
                                               ev.StartDate.Day, ev.StartTime.Hour, ev.StartTime.Minute, 0);
            dbEvent.EndDate = new DateTime(ev.EndDate.Year, ev.EndDate.Month,
                                           ev.EndDate.Day, ev.EndTime.Hour, ev.EndTime.Minute, 0);

            var dbEventParticipants = await _context.EventParticipants.Where(e => e.EventId == id).ToListAsync();

            var newEventParticipants = new List <EventParticipant>();

            if (ev.Users != null)
            {
                foreach (var user in ev.Users)
                {
                    if (!dbEventParticipants.Exists(ep => ep.EventId == id && ep.UserId == user.Id))
                    {
                        newEventParticipants.Add(new EventParticipant {
                            EventId = id, UserId = user.Id
                        });
                    }
                }
            }

            _context.EventParticipants.AddRange(newEventParticipants);

            await _context.SaveChangesAsync();

            var attendees = new List <User>();

            foreach (var newEp in newEventParticipants)
            {
                attendees.Add(_context.EventParticipants.Include(ep => ep.User).FirstOrDefault(ep =>
                                                                                               ep.UserId == newEp.UserId && ep.EventId == newEp.EventId).User);
            }

            _googleCalendarService.UpdateGoogleEvent(dbEvent, attendees);

            return(EventTranslator.ToEventForUpdateDto(dbEvent));
        }
Example #5
0
        public async Task <IActionResult> UpdateEvent(Guid centerId, Guid eventId, [FromBody] EventForUpdateDto eventForUpdate)
        {
            var eventEntity = await _eventRepository.GetEventByIdAsync(eventId);

            if (eventEntity == null)
            {
                return(NotFound());
            }

            if (DateTimeOffset.TryParse(eventForUpdate.ScheduledDate, out var parsedDate))
            {
                if (parsedDate.Date <= DateTimeOffset.Now.Date)
                {
                    return(BadRequest(new
                    {
                        message = "Event can't be scheduled on or before this day"
                    }));
                }

                var eventExist = await _eventRepository.CheckIfEventExistForCenterAsync(centerId, eventId, parsedDate);

                if (eventExist)
                {
                    return(Conflict(new
                    {
                        message = $"An existing event was already scheduled for this center on this day."
                    }));
                }
            }
            else
            {
                return(BadRequest(new
                {
                    message = "Event date is not in correct format"
                }));
            }

            _mapper.Map(eventForUpdate, eventEntity);

            _eventRepository.UpdateEvent(eventEntity);
            await _eventRepository.SaveChangesAsync();

            return(NoContent());
        }
Example #6
0
        public async Task <IActionResult> UpdateEvent(int id, [FromBody] EventForUpdateDto eventToUpdateDto)
        {
            if (id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var eventToUpdate = await _repo.GetEvent(eventToUpdateDto.Id);

            _mapper.Map(eventToUpdateDto, eventToUpdate);

            if (await _repo.SaveAll())
            {
                return(NoContent());
            }


            throw new Exception($"Updating event {id} failed on save");
        }
Example #7
0
        public async Task <IActionResult> UpdateEvent()
        {
            var eventId     = Request.Form["eventId"];
            var eventName   = Request.Form["eventName"];
            var description = Request.Form["description"];
            var happensAt   = Request.Form["happensAt"];
            var signUpLink  = Request.Form["signUpLink"];
            var accepted    = Request.Form["accepted"];

            Event eventInRepo = await this.repo.GetEvent(Convert.ToInt16(eventId));

            EventForUpdateDto eventForUpdateDto = new EventForUpdateDto();

            eventForUpdateDto.EventId     = Convert.ToInt16(eventId);
            eventForUpdateDto.EventName   = eventName;
            eventForUpdateDto.Description = description;
            eventForUpdateDto.HappensAt   = Convert.ToDateTime(happensAt);
            if (accepted == "Przyjęto")
            {
                eventForUpdateDto.Accepted = 1;
            }
            else
            {
                eventForUpdateDto.Accepted = 0;
            }
            eventForUpdateDto.SignUpLink = signUpLink;

            if (Request.Form.Files.Count > 0)
            {
                var file = Request.Form.Files[0];
                if
                (
                    (file.ContentType.ToLower() != "image/jpg" ||
                     file.ContentType.ToLower() != "image/pjpeg" ||
                     file.ContentType.ToLower() != "image/jpeg") &&
                    (Path.GetExtension(file.FileName).ToLower() != ".jpg" ||
                     Path.GetExtension(file.FileName).ToLower() != ".jpeg")
                )
                {
                    string folderName  = "events";
                    string webRootPath = this.hostingEnvironment.WebRootPath;
                    string newPath     = Path.Combine(webRootPath, folderName);
                    if (!Directory.Exists(newPath))
                    {
                        return(BadRequest());
                    }
                    if (file.Length > 0)
                    {
                        string fileName = DateTime.Now.Ticks.ToString();
                        fileName += ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');
                        string fullPath = Path.Combine(newPath, fileName);
                        using (var stream = new FileStream(fullPath, FileMode.Create))
                        {
                            file.CopyTo(stream);
                        }
                        this.repo.DeletePosterFile(eventInRepo);
                        eventForUpdateDto.PosterPhotoUrl = folderName + '\\' + fileName;
                    }
                }
            }
            else
            {
                eventForUpdateDto.PosterPhotoUrl = eventInRepo.PosterPhotoUrl;
            }

            mapper.Map(eventForUpdateDto, eventInRepo);

            if (await this.repo.SaveAll())
            {
                return(Ok());
            }

            return(BadRequest());
        }
Example #8
0
        public async Task <IActionResult> UpdateEvent(int id, [FromBody] EventForUpdateDto ev)
        {
            var result = await _eventService.UpdateEvent(id, ev);

            return(new OkObjectResult(ApiResponse.Create(result)));
        }