Esempio n. 1
0
        public async Task <IActionResult> Create([FromBody] ActionListDto value)
        {
            if (!value.RepresentsNewEntity)
            {
                return(BadRequest());
            }

            var result = await _actionListService.CreateOrUpdate(value);

            if (!result.IsOk())
            {
                return(FromServiceResult(result));
            }

            return(CreatedAtRoute(Routes.GetListById, new { id = result.Value.Id }, result.Value));
        }
Esempio n. 2
0
        public async Task <IActionResult> Update([FromBody] ActionListDto value)
        {
            if (value.RepresentsNewEntity)
            {
                return(BadRequest());
            }

            var result = await _actionListService.CreateOrUpdate(value);

            if (!result.IsOk())
            {
                return(FromServiceResult(result));
            }

            return(NoContent());
        }
        public async Task <ServiceResult <ActionListDto> > CreateOrUpdate(ActionListDto actionListDto)
        {
            ActionList list = actionListDto.RepresentsNewEntity
                ? actionListDto.TranslateTo <ActionList>()
                : (await _listRepository.GetById(actionListDto.Id)).CopyPropertiesFrom(actionListDto);

            if (list == null)
            {
                return(EntityNotFound(actionListDto));
            }

            // TODO: Later on we will do the checks here.
            //       So far we assume everything always works fine.

            list = await _listRepository.AddOrUpdate(list);

            actionListDto.Id = list.Id;

            return(Ok(actionListDto));
        }