コード例 #1
0
        public ActionResult <CategoryReadDto> CreateCategory(CategoryCreateDto categoryCreateDto)
        {
            var model = _mapper.Map <Category>(categoryCreateDto);

            _repository.CreateCategory(model);
            _repository.SaveChanges();

            var readDto = _mapper.Map <CategoryReadDto>(model);

            return(CreatedAtRoute(nameof(GetCategoryById), new { Id = readDto.CategoryId }, readDto));
        }
コード例 #2
0
        public ActionResult UpdateUser([FromRoute] string id, UserCreateDto userUpdateDto)
        {
            var modelFromRepo = _repository.GetUserById(id);

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

            _mapper.Map(userUpdateDto, modelFromRepo);
            _repository.UpdateUser(modelFromRepo);
            _repository.SaveChanges();

            return(NoContent());
        }
コード例 #3
0
        public ActionResult <StorageReadDto> CreateStorage(StorageCreateDto storageCreateDto)
        {
            var model = new Storage()
            {
                IdUser      = _repository.GetUserById(storageCreateDto.UserId),
                StorageName = storageCreateDto.StorageName,
            };

            _repository.CreateStorage(model);
            _repository.SaveChanges();

            var readDto = _mapper.Map <StorageReadDto>(model);

            return(CreatedAtRoute(nameof(GetStorageById), new { Id = readDto.StorageId }, readDto));
        }
コード例 #4
0
        public ActionResult <ExpireReadDto> CreateExpire(ExpireCreateDto expireCreateDto)
        {
            var model = new Expire()
            {
                ExpirationDate = expireCreateDto.ExpirationDate.Date,
                IdUser         = _repository.GetUserById(expireCreateDto.UserId),
                IdItem         = _repository.GetItemById(expireCreateDto.IdItem),
                IdStorage      = _repository.GetStorageById(expireCreateDto.IdStorage),
            };

            _repository.CreateExpire(model);
            _repository.SaveChanges();

            var readDto = _mapper.Map <ExpireReadDto>(model);

            return(CreatedAtRoute(nameof(GetExpireById), new { Id = readDto.ExpireId }, readDto));
        }
コード例 #5
0
        public ActionResult <ItemReadDto> CreateItem(ItemCreateDto itemCreateDto)
        {
            var model = new Item()
            {
                IdCategory = _repository.GetCategoryById(itemCreateDto.CategoryId),
                ItemName   = itemCreateDto.ItemName,
            };

            try
            {
                _repository.CreateItem(model);
                _repository.SaveChanges();
                _logger.LogInformation("Item created by {HttpUser}", HttpContext.User.Identity.Name);
            }
            catch (System.Exception ex)
            {
                _logger.LogInformation("Item creation failed. Exception:", ex.Message);
            }


            var readDto = _mapper.Map <ItemReadDto>(model);

            return(CreatedAtRoute(nameof(GetItemById), new { Id = readDto.ItemId }, readDto));
        }