コード例 #1
0
        public async Task <IActionResult> Create([FromBody] User user)
        {
            var userEntity = await _repository.FindBy <User>(u => u.UserName == user.UserName).FirstOrDefaultAsync();

            if (userEntity == null)
            {
                _repository.Add(user);
            }
            else
            {
                if (userEntity.IsDeleted)
                {
                    userEntity.IsDeleted = false;
                    _repository.Update(userEntity);
                    user = userEntity;
                }
                else
                {
                    return(StatusCode((int)HttpStatusCode.Conflict));
                }
            }

            _repository.Save();
            await _userService.PublishSaveEventAsync(user.Id);

            return(CreatedAtRoute("GetUser", new { id = user.Id }, Mapper.Map <User, UserGetDto>(user)));
        }
コード例 #2
0
ファイル: PlantController.cs プロジェクト: sanket2611/Esuite
        public async Task <IActionResult> Create([FromBody] Plant plant)
        {
            if (_plantService.IsExisting(plant))
            {
                return(StatusCode((int)HttpStatusCode.Conflict));
            }

            _repository.Add(plant);
            _repository.Save();

            await _plantService.PublishSaveEventAsync(plant);

            return(CreatedAtRoute("GetPlant", new { id = plant.Id }, Mapper.Map <Plant, PlantGetDto>(plant)));
        }