Exemple #1
0
        public async Task <ActionResult <EventDayDto> > PutEvent(string name, EventDayDto dto)
        {
            //Eller Required attribute
            if (string.IsNullOrWhiteSpace(dto.Name))
            {
                return(BadRequest("Name required"));
            }

            var eventday = await repo.GetEventAsync(name, false);

            if (eventday is null)
            {
                return(StatusCode(StatusCodes.Status404NotFound));
            }

            mapper.Map(dto, eventday);
            if (await repo.SaveAsync())
            {
                return(Ok(mapper.Map <EventDayDto>(eventday)));
            }
            else
            {
                return(StatusCode(500));
            }
        }
Exemple #2
0
        public async Task <ActionResult <EventDayDto> > PutEvent(string name, EventDayDto dto)
        {
            var eventday = await repo.GetEventAsync(name, false);

            if (eventday is null)
            {
                return(StatusCode(StatusCodes.Status404NotFound));
            }

            mapper.Map(dto, eventday);
            if (await repo.SaveAsync())
            {
                return(Ok(mapper.Map <EventDayDto>(eventday)));
            }
            else
            {
                return(StatusCode(500));
            }
        }
Exemple #3
0
        public async Task <ActionResult <IEnumerable <EventDayDto> > > CreateEvent(EventDayDto dto)
        {
            if (await repo.GetEventAsync(dto.Name, false) != null)
            {
                ModelState.AddModelError("Name", "Name in use");
                return(BadRequest(ModelState));
            }

            var eventday = mapper.Map <Models.Entities.EventDay>(dto);
            await repo.AddAsync(eventday);

            if (await repo.SaveAsync())
            {
                var model = mapper.Map <EventDayDto>(eventday);
                return(CreatedAtAction(nameof(GetEvent), new { name = model.Name }, model));
            }
            else
            {
                return(BadRequest());
            }
        }
Exemple #4
0
        public async Task <ActionResult <EventDayDto> > PutEvent(string name, EventDayDto dto)
        {
            var eventday = await _eventDayRepo.GetEventAsync(name, false);

            if (eventday is null)
            {
                return(StatusCode(StatusCodes.Status404NotFound));
            }

            _mapper.Map(dto, eventday);

            //_eventDayRepo.Update(eventday);
            if (await _eventDayRepo.SaveAsync())
            {
                return(Ok(_mapper.Map <EventDayDto>(eventday)));
            }
            else
            {
                return(new StatusCodeResult(StatusCodes.Status500InternalServerError));
            }
        }
Exemple #5
0
        public async Task <ActionResult <EventDayDto> > CreateEvent(EventDayDto dto)
        {
            if (await _eventDayRepo.GetEventAsync(dto.Name, false) is not null)
            {
                ModelState.AddModelError("Name", "Name already in use");
                return(BadRequest(ModelState));
            }

            var eventday = _mapper.Map <EventDay>(dto);
            await _eventDayRepo.AddAsync(eventday);

            if (await _eventDayRepo.SaveAsync())
            {
                var model = _mapper.Map <EventDayDto>(eventday);
                return(CreatedAtAction(nameof(GetEvent), new { name = model.Name }, model));
            }
            else
            {
                return(new StatusCodeResult(StatusCodes.Status500InternalServerError));
            }
        }