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))); }
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))); }