public IHttpActionResult PostPetView(PetView petView) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.PetViews.Add(petView); try { db.SaveChanges(); } catch (DbUpdateException) { if (PetViewExists(petView.PetName)) { return(Conflict()); } else { throw; } } return(CreatedAtRoute("DefaultApi", new { id = petView.PetName }, petView)); }
public IHttpActionResult PutPetView(string id, PetView petView) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != petView.PetName) { return(BadRequest()); } db.Entry(petView).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!PetViewExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public ActionResult AddPet() { List <Client> allClients = _repository.GetClients().ToList(); var newPet = new PetView(); newPet.mastersList = allClients; return(View(newPet)); }
public async Task <IHttpActionResult> GetPetView(string PetName, int id) { PetView petView = await db.PetViews.FirstOrDefaultAsync(p => p.PetName == PetName && p.OwnerID == id); if (petView == null) { return(NotFound()); } return(Ok(petView)); }
public async Task <IHttpActionResult> GetPetView(int id) { PetView petView = await db.PetViews.FindAsync(id); if (petView == null) { return(NotFound()); } return(Ok(petView)); }
public HttpResponseMessage Get([FromUri] int id) { var pet = new PetView { Id = id.ToString(), Name = "John Doe", BirthDate = System.DateTime.Now }; return(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(JsonConvert.SerializeObject(pet), System.Text.Encoding.UTF8, "application/json") }); }
private List <PetView> PetToPetViewMapper(List <Pet> currentPets) { List <PetView> allPets = new List <PetView>(); foreach (Pet pet in currentPets) { PetView tempPet = (PetView)_mapper.Map(pet, typeof(Pet), typeof(PetView)); allPets.Add(tempPet); } return(allPets); }
public IHttpActionResult Post([FromBody] PetView pet, HttpRequestMessage request) { try { PetManager.SavePet(pet); } catch (System.Exception ex) { return(BadRequest(ex.Message)); } return(Ok()); }
public IHttpActionResult DeletePetView(string id) { PetView petView = db.PetViews.Find(id); if (petView == null) { return(NotFound()); } db.PetViews.Remove(petView); db.SaveChanges(); return(Ok(petView)); }
public async Task <IHttpActionResult> DeletePetView(int id) { PetView petView = await db.PetViews.FindAsync(id); if (petView == null) { return(NotFound()); } db.PetViews.Remove(petView); await db.SaveChangesAsync(); return(Ok(petView)); }
public static void SavePet(PetView petToSave) { PetDAL petHandler = new PetDAL(); Pet pet = new Pet { name = petToSave.Name, birthDate = petToSave.BirthDate, breed = petToSave.Breed, description = petToSave.Description, specie = petToSave.SpecieName, createdDate = DateTime.Now, createdBy = Constant.ADMIN_EMAIL, userId = new Guid(petToSave.UserId), }; petHandler.Post(pet); }
public ActionResult AddPet(PetView newPet) { bool anyPetName = _repository.GetPets().Any(p => string.Compare(p.Name, newPet.name) == 0); bool anyPetMaster = _repository.GetPets().Any(p => string.Compare(p.Master.ToString(), newPet.master.ToString()) == 0); if (anyPetName && anyPetMaster) { ModelState.AddModelError("Name", "Этот питомец уже зарегестрирован"); } if (ModelState.IsValid) { var currentPet = (Pet)_mapper.Map(newPet, typeof(PetView), typeof(Pet)); this.SavePet(currentPet); return(RedirectToAction("Index", "Success")); } newPet.mastersList = _repository.GetClients().ToList(); return(View(newPet)); }