Пример #1
0
        public override IActionResult Create([FromBody] TEntityForCreacteDto entityToCreate)
        {
            var entityFromRepo = Mapper.Map <TEntityForCreacteDto, TEntity>(entityToCreate);

            _crudService.Create(entityFromRepo);

            var tags = Mapper.Map <ICollection <Tag> >(entityToCreate.Tags);

            TagsManager.AddTags(entityFromRepo.Tags, tags, entityFromRepo.Id, _tagService);

            if (!_crudService.Save())
            {
                throw new Exception("Creating entity failed on save.");
            }

            return(Ok());
        }
Пример #2
0
        public override IActionResult Update(Guid id, [FromBody] TEntityForCreacteDto entityToUpdate)
        {
            var entityFromRepo = _crudService.Get(id, IncludeExpression, true);

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

            Mapper.Map(entityToUpdate, entityFromRepo);

            var tags = Mapper.Map <ICollection <Tag> >(entityToUpdate.Tags);

            TagsManager.AddTags(entityFromRepo.Tags, tags, entityFromRepo.Id, _tagService);

            if (!_crudService.Save())
            {
                throw new Exception($"Updating entity {id} failed on save.");
            }

            return(NoContent());
        }