public AssignPetResponse AssignPet(AssignPetRequest request, int id) { var volunteerCheck = _context.Volunteers.FirstOrDefault(p => p.IdVolunteer == id); var petCheck = _context.Pets.FirstOrDefault(p => p.IdPet == request.IdPet); if (volunteerCheck == null) { throw new VolunteerDoesnotExist(); } if (petCheck == null) { throw new PetDoesntExist(); } if (volunteerCheck.IdSupervisor != null) { throw new VolunteerHasSupervisor(); } var pet = new Volunteer_Pet() { IdVolunteer = id, IdPet = request.IdPet, DateAccepted = request.DateAccepted }; _context.Volunteer_Pets.Add(pet); _context.SaveChanges(); return(new AssignPetResponse() { IdVolunteer = id, IdPet = request.IdPet, DateAccepted = request.DateAccepted }); }
public void AssignPetToVolunteer(PetRequest request) { if (_volunteerDbContext.Volunteers.Where(v => v.IdVolunteer == request.idVolunteer).Count() != 1) { throw new Exception(); } if (_volunteerDbContext.Pets.Where(pet => pet.IdPet == request.idPet).Count() != 1) { throw new Exception(); } if (_volunteerDbContext.Volunteers.Where(v => v.IdVolunteer == request.idVolunteer && v.IdSupervisor == null).Count() != 1) { throw new Exception(); } using (var trans = _volunteerDbContext.Database.BeginTransaction()) { Volunteer_Pet volunteer_Pet = new Volunteer_Pet() { idPet = request.idPet, idVolunteer = request.idVolunteer, DateAccepted = DateTime.Now }; _volunteerDbContext.Add <Volunteer_Pet>(volunteer_Pet); _volunteerDbContext.SaveChanges(); trans.Commit(); } }
public ActionResult Create([Bind(Include = "Id,name")] Organization organization) { try { if (ModelState.IsValid) { db.organizations.Add(organization); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(organization)); } catch { return(View("Error")); } }
public ActionResult Create([Bind(Include = "Id,name,description,beginDate")] Project project) { try { if (ModelState.IsValid) { db.projects.Add(project); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(project)); } catch { return(View("Error")); } }
public ActionResult DeleteConfirmed(int id) { try { TimeSheet timeSheet = db.timeSheets.Find(id); db.timeSheets.Remove(timeSheet); db.SaveChanges(); return(RedirectToAction("Index")); } catch { return(View("Error")); } }