public override int UpdateUID(PetProfileDTO dt) { using (var context = new PHCEntities()) { try { PetProfile pp = context.PetProfiles.Where(p => p.PID == dt.PID).SingleOrDefault(); if (pp != null) { pp.UID = dt.UID; context.SaveChanges(); int c = pp.PID; return(c); } else { return(0); } } catch (Exception ex) { throw ex; } } }
async void Done(object sender, EventArgs e) { PetProfile petprofile = new PetProfile() { Name = name_entry.Text, Type = type_picker.SelectedItem.ToString(), Gender = gender_picker.SelectedItem.ToString(), Age = age_picker.SelectedItem.ToString(), RFID = rfid_entry.Text, Image = image }; SQLiteConnection conn = new SQLiteConnection(App.DatabaseLocation); conn.CreateTable <PetProfile>(); int rows = conn.Insert(petprofile); conn.Close(); if (rows > 0) { await DisplayAlert("Success", "You have added a pet", "Ok"); } else { await DisplayAlert("Failure", "Your pet was not added", "OK"); } await Navigation.PopToRootAsync(); }
public async Task <PetProfileResponse> SaveAsync(int cityId, int provinceId, PetProfile petProfile) { var existingProvince = await _provinceRepository.FindById(provinceId); var existingCity = await _cityRepository.FindById(cityId); if (existingProvince == null) { return(new PetProfileResponse("Province not found, a profile needs a province to exist")); } if (existingCity == null) { return(new PetProfileResponse("City not found, a profile needs a city to exist")); } if (existingCity.ProvinceId != provinceId) { return(new PetProfileResponse("The City does not exist in the province")); } try { await _petProfileRepository.AddAsync(petProfile); await _unitOfWork.CompleteAsync(); return(new PetProfileResponse(petProfile)); } catch (Exception ex) { return(new PetProfileResponse($"An error ocurred while saving PetProfile: {ex.Message}")); } }
public ActionResult Edit(int id, PetProfile petProfile, HttpPostedFileBase file) { int imageid; PODBProjectEntities entities = new PODBProjectEntities(); String userId = User.Identity.GetUserId(); PostPhoto photo = new PostPhoto(); String path = photo.PostPhotoPet(file); if (file != null) { imageid = entities.Images.Where(e => e.imagePath.Equals(path)).FirstOrDefault().imageID; } else { imageid = entities.Announcements.Where(e => e.announceId.Equals(id)).FirstOrDefault().imageID; } try { using (PODBProjectEntities edit = new PODBProjectEntities()) { petProfile.Id = User.Identity.GetUserId(); petProfile.imageID = 1; edit.Entry(petProfile).State = EntityState.Modified; edit.SaveChanges(); return(RedirectToAction("Index")); } } catch { return(View()); } }
public IActionResult DisplayNotMyPetProfileDetails(int id) { //PetProfile pet = _repo.PetProfile.GetPetAndIncludeAll().Where(p => p.Id == id).FirstOrDefault(); PetProfile petProfile = _repo.PetProfile.GetPetByIdIncludeAll(id); ViewModelPetProfile petProfileViewing = new ViewModelPetProfile(); petProfileViewing.PetProfileId = id; petProfileViewing.Name = petProfile.Name; petProfileViewing.Age = petProfile.Age; petProfileViewing.PetOwnerId = petProfile.PetOwnerId; ViewData["PetType"] = new SelectList(_repo.PetType.GetAllPetTypes(), "Id", "TypeName"); Dictionary <int, string> genderDictionary = CreateNullableBoolDictionary("N/A", "Male", "Female"); ViewData["GenderSelection"] = new SelectList(genderDictionary, "Key", "Value"); Dictionary <int, string> adoption = CreateNullableBoolDictionary("N/A", "Adopted", "Avaliable"); ViewData["AdoptionStatus"] = new SelectList(adoption, "Key", "Value"); return(View(petProfileViewing)); }
async void DoneEdit(object sender, EventArgs e) { SQLiteConnection conn = new SQLiteConnection(App.DatabaseLocation); conn.Query <PetProfile>("select * from PetProfile where id=?", tempid); PetProfile petprofile = new PetProfile() { id = tempid, Name = name_entry.Text, Gender = gender_picker.SelectedItem.ToString(), Type = type_picker.SelectedItem.ToString(), Age = age_picker.SelectedItem.ToString(), RFID = rfid_entry.Text, Image = image }; conn.Update(petprofile); conn.Close(); await DisplayAlert("Success", "Pet information saved", "Ok"); await Navigation.PopToRootAsync(); }
public IActionResult EditPetProfile(int id) { PetProfile petProfile = _repo.PetProfile.GetPetByIdIncludeAll(id); var userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier); var petOwnerId = _repo.PetOwner.GetPetOwnerById(userId).Id; ViewModelPetProfile petProfileUpdating = new ViewModelPetProfile(); petProfileUpdating.PetOwnerId = petOwnerId; petProfileUpdating.PetProfileId = id; petProfileUpdating.Name = petProfile.Name; petProfileUpdating.Age = petProfile.Age; ViewData["PetType"] = new SelectList(_repo.PetType.GetAllPetTypes(), "Id", "TypeName"); Dictionary <int, string> genderDictionary = CreateNullableBoolDictionary("N/A", "Male", "Female"); ViewData["GenderSelection"] = new SelectList(genderDictionary, "Key", "Value"); Dictionary <int, string> adoption = CreateNullableBoolDictionary("N/A", "Adopted", "Avaliable"); ViewData["AdoptionStatus"] = new SelectList(adoption, "Key", "Value"); //petProfile.PetOwner = new PetOwner(); return(View(petProfileUpdating)); }
public IActionResult CreatePetProfile(ViewModelPetProfile viewModel) { try { var userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier); var petOwnerId = _repo.PetOwner.GetPetOwnerById(userId).Id; string uniqueFileName = UploadedPicture(viewModel); PetProfile petProfile = new PetProfile { Name = viewModel.Name, Age = viewModel.Age, IsMale = viewModel.IsMale, IsAdopted = viewModel.IsAdopted, PetOwnerId = petOwnerId, PetTypeId = viewModel.PetTypeId, ProfilePicture = uniqueFileName, }; _repo.PetProfile.CreatePetProfile(petOwnerId, petProfile.PetTypeId, petProfile.Name, petProfile.Age, petProfile.IsMale, petProfile.IsAdopted, uniqueFileName); _repo.Save(); return(RedirectToAction(nameof(DisplayPetProfiles))); } catch { ViewData["PetType"] = new SelectList(_repo.PetType.GetAllPetTypes(), "Id", "TypeName"); Dictionary <int, string> genderDictionary = CreateNullableBoolDictionary("N/A", "Male", "Female"); ViewData["GenderSelection"] = new SelectList(genderDictionary, "Key", "Value"); Dictionary <int, string> adoption = CreateNullableBoolDictionary("N/A", "Adopted", "Avaliable"); ViewData["AdoptionStatus"] = new SelectList(adoption, "Key", "Value"); return(View(viewModel)); } }
public IActionResult DeletePetProfile(ViewModelPetProfile viewModel) { //PetProfile petProfileToDelete = _repo.PetProfile.GetPetAndIncludeAll().FirstOrDefault(s => s.Id == petProfile.Id); //_repo.PetProfile.Delete(_repo.PetProfile.GetPetById(petProfile.Id)); //_repo.Save(); //return RedirectToAction(nameof(DisplayPetProfiles)); PetProfile petProfileDeleting = _repo.PetProfile.GetPetAndIncludeAll().FirstOrDefault(s => s.Id == viewModel.PetProfileId); //petProfileDeleting.Id = viewModel.PetProfileId; _repo.PetProfile.Delete(petProfileDeleting); _repo.Save(); return(RedirectToAction(nameof(DisplayPetProfiles))); }
public ActionResult Delete(int id, FormCollection collection) { try { using (PODBProjectEntities entities = new PODBProjectEntities()) { PetProfile petProfile = entities.PetProfiles.Where(e => e.petId.Equals(id)).FirstOrDefault(); entities.PetProfiles.Remove(petProfile); entities.SaveChanges(); return(RedirectToAction("Index")); } } catch { return(View()); } }
public async Task SaveAsyncWhenSaveReturnsSaved() { //Arrange var mockPetProfileRepository = GetDefaultIPetProfileRepositoryInstance(); var mockPetOwnerRepository = GetDefaultIPetOwnerRepositoryInstance(); var mockPetIllnessRepository = GetDefaultIPetIllnessRepositoryInstance(); var mockPetTreatmentRepository = GetDefaultIPetTreatmentRepositoryInstance(); var mockUnitOfWork = GetDefaultIUnitOfWorkInstance(); var mockCityRepository = GetDefaultICityRepositoryInstance(); var mockProvinceRepository = GetDefaultIProvinceRepositoryInstance(); Province province = new Province { Id = 1, Name = "Lima" }; City city = new City { Id = 10, Name = "SJL", ProvinceId = 1 }; PetProfile petProfile = new PetProfile { Id = 10, Name = "Toby" }; mockProvinceRepository.Setup(p => p.AddAsync(province)) .Returns(Task.FromResult <Province>(province)); mockProvinceRepository.Setup(p => p.FindById(1)) .Returns(Task.FromResult <Province>(province)); mockCityRepository.Setup(r => r.AddAsync(city)) .Returns(Task.FromResult <City>(city)); mockCityRepository.Setup(p => p.FindById(10)) .Returns(Task.FromResult <City>(city)); mockPetProfileRepository.Setup(r => r.AddAsync(petProfile)) .Returns(Task.FromResult <PetProfile>(petProfile)); var service = new PetProfileService(mockUnitOfWork.Object, mockPetTreatmentRepository.Object, mockPetIllnessRepository.Object , mockPetOwnerRepository.Object, mockPetProfileRepository.Object, mockProvinceRepository.Object, mockCityRepository.Object); //Act PetProfileResponse result = await service.SaveAsync(10, 1, petProfile); //Assert result.Resource.Should().Be(petProfile); }
public IActionResult EditPetProfile(int id, ViewModelPetProfile viewModel) { string uniqueFileName = UploadedPicture(viewModel); PetProfile petProfile = _repo.PetProfile.FindByCondition(p => p.Id == id).FirstOrDefault(); petProfile.Name = viewModel.Name; petProfile.Age = viewModel.Age; petProfile.IsMale = viewModel.IsMale; petProfile.IsAdopted = viewModel.IsAdopted; petProfile.PetOwnerId = viewModel.PetOwnerId; petProfile.PetTypeId = viewModel.PetTypeId; petProfile.ProfilePicture = uniqueFileName; _repo.PetProfile.Update(petProfile); _repo.Save(); return(RedirectToAction(nameof(DisplayPetProfiles))); }
public ActionResult Create(PetProfileModel petProfile, HttpPostedFileBase file) { PODBProjectEntities entities = new PODBProjectEntities(); PostPhoto photo = new PostPhoto(); String path = photo.PostPhotoPet(file); int ImageID = entities.Images.Where(e => e.imagePath.Equals(path)).FirstOrDefault().imageID; if (petProfile.mChipId == null) { petProfile.mChipId = "Not Microchipped"; } var pet = new PetProfile { Id = User.Identity.GetUserId(), imageID = ImageID, petName = petProfile.petName, petType = petProfile.petType, petBreed = petProfile.petBreed, gender = petProfile.gender, mChipId = petProfile.mChipId, mChipStatus = petProfile.mChipStatus, nueterStatus = petProfile.nueterStatus }; entities.PetProfiles.Add(pet); try { entities.SaveChanges(); } catch (DbEntityValidationException ex) { foreach (var entityValidationErrors in ex.EntityValidationErrors) { foreach (var validationError in entityValidationErrors.ValidationErrors) { Response.Write("Property: " + validationError.PropertyName + " Error: " + validationError.ErrorMessage); } } } return(RedirectToAction("Index")); }
public async Task <PetProfileResponse> UpdateAsync(int id, PetProfile petProfile) { var existingPetProfile = await _petProfileRepository.FindById(id); if (existingPetProfile == null) { return(new PetProfileResponse("Pet Profile not found")); } existingPetProfile.BirthDate = petProfile.BirthDate; existingPetProfile.Name = petProfile.Name; try { _petProfileRepository.Update(existingPetProfile); await _unitOfWork.CompleteAsync(); return(new PetProfileResponse(existingPetProfile)); } catch (Exception ex) { return(new PetProfileResponse($"An error ocurred while updating PetProfile: {ex.Message}")); } }
public IActionResult DeletePetProfile(int id) { PetProfile petProfile = _repo.PetProfile.GetPetByIdIncludeAll(id); ViewModelPetProfile petProfileDeleting = new ViewModelPetProfile(); petProfileDeleting.PetProfileId = id; petProfileDeleting.Name = petProfile.Name; petProfileDeleting.Age = petProfile.Age; ViewData["PetType"] = new SelectList(_repo.PetType.GetAllPetTypes(), "Id", "TypeName"); Dictionary <int, string> genderDictionary = CreateNullableBoolDictionary("N/A", "Male", "Female"); ViewData["GenderSelection"] = new SelectList(genderDictionary, "Key", "Value"); Dictionary <int, string> adoption = CreateNullableBoolDictionary("N/A", "Adopted", "Avaliable"); ViewData["AdoptionStatus"] = new SelectList(adoption, "Key", "Value"); return(View(petProfileDeleting)); }
public override PetProfileDTO SavePetDetSignUp(PetProfileDTO dto) { using (var context = new PHCEntities()) { try { PetProfileDTO pdto = new PetProfileDTO(); PetProfile pp = new PetProfile(); pp.UID = dto.UID; pp.PetName = dto.PetName; pp.PetBreed = dto.PetBreed; pp.PetCategory = dto.pcid.ToString(); context.AddToPetProfiles(pp); context.SaveChanges(); pdto.PID = pp.PID; return(pdto); } catch (Exception ex) { throw ex; } } }
public static PetProfileDto ToDto(this PetProfile pet) { if (pet == null) { return(null); } return(new PetProfileDto() { Id = pet.Id, OwnerId = pet.OwnerId, AvgLikeCount = pet.AvgLikeCount, Breed = pet.Breed, DateOfBirth = pet.DateOfBirth, Gender = pet.Gender == null ? null : pet.Gender.ToString(), Img = pet.Img, IsReadyForSex = pet.IsReadyForSex, IsSale = pet.IsSale, IsShare = pet.IsShare, Location = pet.Location, Name = pet.Name, Type = pet.Type }); }
public void Update(PetProfile petProfile) { _context.PetProfiles.Update(petProfile); }
public void Remove(PetProfile petProfile) { _context.PetProfiles.Remove(petProfile); }
public async Task AddAsync(PetProfile petProfile) { await _context.PetProfiles.AddAsync(petProfile); }