예제 #1
0
        public async Task <ActionResult> Store([FromBody] NoticeViewModel model)
        {
            ValidateRequest(model);
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var notice = model.MapEntity(_mapper, CurrentUserId);

            notice.Order = model.Active ? 0 : -1;

            notice = await _noticesService.CreateAsync(notice);

            return(Ok(notice.MapViewModel(_mapper)));
        }
예제 #2
0
        public async Task <ActionResult> Update(int id, [FromBody] NoticeViewModel model)
        {
            var existingEntity = await _noticesService.GetByIdAsync(id);

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

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

            var notice = model.MapEntity(_mapper, CurrentUserId);

            notice.Order = model.Active ? 0 : -1;

            await _noticesService.UpdateAsync(existingEntity, notice);

            return(Ok(notice.MapViewModel(_mapper)));
        }