public async Task <Result> UpdateSpecie(int id, SpecieCreateModel model) { try { Specie entity = await _specieRepository.GetById(id); _mapper.MapUpdate(entity, model); return(await _specieRepository.Update(entity)); } catch (Exception ex) { _logger.LogError(ex, $"Problems with updating Specie by id : {id}"); return(new Result { Success = false, ErrorCode = ErrorCode.InternalError, }); } }
public ActionResult EditSpecie(int specieId, string name) { if (String.IsNullOrEmpty(name)) { return(Json(new { Result = "Fail, specie name is required" })); } Specie type = _SpecieRepo.GetByName(name); if (type != null && type.id != specieId) { return(Json(new { Result = "Fail, specie " + name + " is already exits in the system" })); } Specie editType = _SpecieRepo.GetById(specieId); editType.name = name; _SpecieRepo.Update(editType); return(Json(new { Result = "Success" })); }
public async Task <SpecieResponse> UpdateAsync(int id, Specie specie) { var existingSpecie = await _specieRepository.FindById(id); if (existingSpecie == null) { return(new SpecieResponse("Specie not found")); } existingSpecie.Name = specie.Name; try { _specieRepository.Update(existingSpecie); await _unitOfWork.CompleteAsync(); return(new SpecieResponse(existingSpecie)); } catch (Exception ex) { return(new SpecieResponse($"An error ocurred while updating specie: {ex.Message}")); } }