public async Task <IActionResult> Update([FromBody] Plant plant) { if (_plantService.IsExisting(plant)) { return(StatusCode((int)HttpStatusCode.Conflict)); } var dbPlant = _repository.GetById <Plant>(plant.Id); if (dbPlant == null) { return(NotFound()); } dbPlant.Name = plant.Name; dbPlant.GaiaCode = plant.GaiaCode; dbPlant.CountryId = plant.CountryId; dbPlant.SOAId = plant.SOAId; _repository.Update(dbPlant); _repository.Save(); await _plantService.PublishSaveEventAsync(dbPlant); return(NoContent()); }
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))); }