private void MapUpdatedFields(AnimalContract updatedAnimal, AnimalContract oldAnimal) { oldAnimal.Name = updatedAnimal.Name; oldAnimal.Weight = updatedAnimal.Weight; oldAnimal.Age = updatedAnimal.Age; oldAnimal.AnimalType = updatedAnimal.AnimalType; oldAnimal.AdoptedBy = updatedAnimal.AdoptedBy; }
public void Add(AnimalContract animal) { try { using (var context = new DatabaseContext()) { context.Animals.Add(animal); context.SaveChanges(); } } catch (Exception e) { throw e; } }
public void Edit(AnimalContract updatedAnimal) { try { using (var context = new DatabaseContext()) { var oldAnimal = context.Animals.First(x => x.ID == updatedAnimal.ID); MapUpdatedFields(updatedAnimal, oldAnimal); context.SaveChanges(); } } catch (Exception e) { throw e; } }
public OperationResult Edit(AnimalContract animal) { try { if (animal == null) { return(new OperationResult(false, "Null contract.")); } _animalRepository.Edit(animal); return(new OperationResult(true, "Animal edited.")); } catch (Exception e) { return(new OperationResult(false, e.Message)); } }
public OperationResult Add(AnimalContract animal) { try { if (animal == null) { return(new OperationResult(false, "Null contract.")); } animal.ID = Guid.NewGuid(); animal.CreatedOn = DateTime.Now; _animalRepository.Add(animal); return(new OperationResult(true, "Animal added.")); } catch (Exception e) { return(new OperationResult(false, e.Message)); } }
public JsonResult Edit(AnimalContract animal) { var result = _animalService.Edit(animal); return(Json(result, JsonRequestBehavior.AllowGet)); }
public JsonResult Add(AnimalContract animal) { var result = _animalService.Add(animal); return(Json(result)); }
public AdoptionContract(AdopterContract Adopter, AnimalContract Animal) { this.Adopter = Adopter; this.Animal = Animal; }