public ActionResult Index() { UserListModel model = new UserListModel(); var _db = new SquareDanceDb(); try { var users = _db.Users.ToList(); foreach (var user in users) { var userModel = new UserProfileModel(user); model.Users.Add(userModel); } } catch (Exception e) { logger.Error("An error occurred while Index. Error: " + e); } finally { _db.Dispose(); } return(View(model)); }
public ActionResult ServiceOptions(ServiceOptionsModel model) { if (ModelState.IsValid) { var _db = new SquareDanceDb(); try { var userId = User.Identity.GetUserId(); var serviceOptions = _db.ServiceAndRate.Find(userId); if (serviceOptions != null) { serviceOptions.DayCareDogs = model.DayCareDogs; serviceOptions.FullTimeWeek = model.FullTimeWeek; serviceOptions.PottyBreaks = model.PottyBreaks; serviceOptions.Flexible = model.Flexible; serviceOptions.DropInVisits = model.DropInVisits; serviceOptions.DogWalkingTime = model.DogWalkingTime; _db.SaveChanges(); } } catch (Exception e) { logger.Error("An error occurred while SaveServiceOption. Error: " + e); } finally { _db.Dispose(); } return(RedirectToAction("PetPreferences", "Sitter")); } return(View(model)); }
public JsonResult DeleteImage(Guid id) { var _db = new SquareDanceDb(); try { var image = _db.PetImage.Find(id); _db.PetImage.Remove(image); _db.SaveChanges(); var path = Path.Combine(Server.MapPath("~/Pic/"), image.Name); if (System.IO.File.Exists(path)) { System.IO.File.Delete(path); } return(Json(new { Success = true }, JsonRequestBehavior.AllowGet)); } catch (Exception e) { logger.Error("An error occurred while DeleteImage. Error: " + e); return(Json(new { Success = false }, JsonRequestBehavior.AllowGet)); } finally { _db.Dispose(); } }
public ActionResult Rates(RateModel model) { if (ModelState.IsValid) { var _db = new SquareDanceDb(); try { var userId = User.Identity.GetUserId(); var rates = _db.ServiceAndRate.Find(userId); if (rates != null) { rates.DogBoardingFee = model.DogBoardingFee; rates.DoggyDayCareFee = model.DoggyDayCareFee; rates.DogWalkingFee = model.DogWalkingFee; rates.DropInVisitsFee = model.DropInVisitsFee; rates.HouseSittingFee = model.HouseSittingFee; _db.SaveChanges(); } } catch (Exception e) { logger.Error("An error occurred while SaveRates. Error: " + e); } finally { _db.Dispose(); } return(RedirectToAction("ServiceOptions", "Sitter")); } return(View(model)); }
public ActionResult UpdateProfileImage() { var _db = new SquareDanceDb(); try { foreach (string file in Request.Files) { var fileContent = Request.Files[file]; if (fileContent.ContentLength > 0) { var fileName = Guid.NewGuid().ToString() + fileContent.FileName; var path = Path.Combine(Server.MapPath("~/Pic/"), fileName); fileContent.SaveAs(path); var userId = User.Identity.GetUserId(); var user = _db.Users.Find(userId); if (user != null) { var deletePath = user.ProfileImagePath; user.ProfileImagePath = Path.Combine("http://www.liar114.com/Pic/", fileName); _db.SaveChanges(); if (!string.IsNullOrEmpty(deletePath)) { deletePath = Path.Combine(Server.MapPath($"~{deletePath}")); if (System.IO.File.Exists(deletePath)) { System.IO.File.Delete(deletePath); } } } } } } catch (Exception e) { logger.Error("An error occurred while UpdateProfileImage. Error: " + e); } finally { _db.Dispose(); } return(RedirectToAction("UserProfile")); }
public ActionResult Services(ServiceModel model) { if (ModelState.IsValid) { var _db = new SquareDanceDb(); try { var sitter = _db.Sitter.Find(model.UserId); if (sitter == null) { var newSitter = new Sitter(); { newSitter.UserId = model.UserId; } _db.Sitter.Add(newSitter); _db.SaveChanges(); } var services = _db.ServiceAndRate.Find(model.UserId); if (services == null) { var newServices = new ServiceAndRate(model); _db.ServiceAndRate.Add(newServices); _db.SaveChanges(); } else { services.DogBoarding = model.DogBoarding; services.HouseSitting = model.HouseSitting; services.DropInVisits = model.DropInVisits; services.DogWalking = model.DogWalking; services.DoggyDayCare = model.DoggyDayCare; _db.SaveChanges(); } } catch (Exception e) { logger.Error("An error occurred while SaveServices. Error: " + e); } finally { _db.Dispose(); } return(RedirectToAction("Rates", "Sitter")); } return(View(model)); }
public ActionResult Search(string address) { var _db = new SquareDanceDb(); var model = new SitterSearchModel(); try { if (address != null) { var point = new GoogleLocationService().GetLatLongFromAddress((!string.IsNullOrEmpty(address) && address != null) ? address : ""); if (point != null) { model.AddressLatitude = point.Latitude; model.AddressLongitude = point.Longitude; var coord = DbGeography.FromText($"POINT({point.Longitude} {point.Latitude})"); if (coord != null) { var sitters = _db.Sitter.OrderBy(x => x.User.Location.Distance(coord)).Take(20).ToList(); foreach (var sitter in sitters) { var sitterModel = new SitterModel(sitter); model.Sitters.Add(sitterModel); } } } } } catch (Exception e) { logger.Error("An error occurred while Index. Error: " + e); } finally { _db.Dispose(); } return(View(model)); }
public JsonResult AddImagesToPet(Guid Id) { var _db = new SquareDanceDb(); try { foreach (string file in Request.Files) { var fileContent = Request.Files[file]; if (fileContent.ContentLength > 0) { var fileName = Guid.NewGuid().ToString() + fileContent.FileName; var path = Path.Combine(Server.MapPath("~/Pic/"), fileName); fileContent.SaveAs(path); var petImage = new PetImage(); { petImage.PetId = Id; petImage.Path = Path.Combine("http://www.liar114.com/Pic/", fileName); petImage.Name = fileName; petImage.Description = "asfasd"; } _db.PetImage.Add(petImage); } } _db.SaveChanges(); return(Json(_PetImagesDetail(Id), JsonRequestBehavior.AllowGet)); } catch (Exception e) { logger.Error("An error occurred while AddImagesToPet. Error: " + e); Response.StatusCode = (int)HttpStatusCode.BadRequest; return(Json("错误", JsonRequestBehavior.AllowGet)); } finally { _db.Dispose(); } }
public JsonResult AddDog(PetModel model) { var _db = new SquareDanceDb(); try { var newDog = new Pet(model); foreach (string file in Request.Files) { var fileContent = Request.Files[file]; if (fileContent.ContentLength > 0) { var fileName = Guid.NewGuid().ToString() + fileContent.FileName; var path = Path.Combine(Server.MapPath("~/Pic/"), fileName); fileContent.SaveAs(path); var petImage = new PetImage(); { petImage.PetId = newDog.Id; petImage.Path = Path.Combine("http://www.liar114.com/Pic/", fileName); petImage.Name = fileName; petImage.Description = "asfasd"; } newDog.PetImages.Add(petImage); } } newDog = _db.Pet.Add(newDog); _db.SaveChanges(); } catch (Exception e) { logger.Error("An error occurred while UploadDog. Error: " + e); } finally { _db.Dispose(); } return(Json(new { Success = true }, JsonRequestBehavior.AllowGet)); }
public ActionResult EditPet(PetModel model) { var _db = new SquareDanceDb(); try { var pet = _db.Pet.Find(model.Id); var updatedPet = new Pet(model); _db.Entry(pet).CurrentValues.SetValues(updatedPet); _db.SaveChanges(); } catch (Exception e) { logger.Error("An error occurred while EditPet. Error: " + e); } finally { _db.Dispose(); } return(RedirectToAction("PetDetail", new { petId = model.Id })); }
public ActionResult _PetImagesDetail(Guid id) { var _db = new SquareDanceDb(); var model = new PetModel(); try { var pet = _db.Pet.Find(id); model = new PetModel(pet); } catch (Exception e) { logger.Error("An error occurred while AddImagesToPet. Error: " + e); } finally { _db.Dispose(); } return(PartialView(model)); }
public ActionResult Details() { var _db = new SquareDanceDb(); var model = new SitterProfileModel(); try { var userId = User.Identity.GetUserId(); var details = _db.SitterProfile.Find(userId); model = new SitterProfileModel(details); } catch (Exception e) { logger.Error("An error occurred while Details. Error: " + e); } finally { _db.Dispose(); } return(View(model)); }
public ActionResult Detail(string sitterId) { var _db = new SquareDanceDb(); try { var sitter = _db.Sitter.Find(sitterId); var serviceAndRate = _db.ServiceAndRate.Find(sitterId); var sitterProfile = _db.SitterProfile.Find(sitterId); var model = new SitterDetailModel(sitter); if (serviceAndRate != null) { model.Rate = new RateModel(serviceAndRate); model.Service = new ServiceModel(serviceAndRate); model.ServiceOptions = new ServiceOptionsModel(serviceAndRate); model.PetPreferences = new PetPreferencesModel(serviceAndRate); } if (sitterProfile != null) { model.SitterProfile = new SitterProfileModel(sitterProfile); } return(View(model)); } catch (Exception e) { logger.Error("An error occurred while Detail. Error: " + e); return(View("Search")); } finally { _db.Dispose(); } }
public ActionResult SavePetPreferences(PetPreferencesModel model) { var _db = new SquareDanceDb(); try { var userId = User.Identity.GetUserId(); var petPreferences = _db.ServiceAndRate.Find(userId); if (petPreferences != null) { petPreferences.BoardingSmallDog = model.BoardingSmallDog; petPreferences.BoardingMediumDog = model.BoardingMediumDog; petPreferences.BoardingLargeDog = model.BoardingLargeDog; petPreferences.BoardingGiantDog = model.BoardingGiantDog; petPreferences.BoardingUnderOne = model.BoardingUnderOne; petPreferences.HostDifferentFamily = model.HostDifferentFamily; petPreferences.HostMaleNotNeutered = model.HostMaleNotNeutered; petPreferences.HostFemaleNotSpayed = model.HostFemaleNotSpayed; petPreferences.HostNeedCrateTrained = model.HostNeedCrateTrained; petPreferences.HouseSmallDog = model.HouseSmallDog; petPreferences.HouseMediumDog = model.HouseMediumDog; petPreferences.HouseLargeDog = model.HouseLargeDog; petPreferences.HouseGiantDog = model.HouseGiantDog; petPreferences.HouseUnderOne = model.HouseUnderOne; _db.SaveChanges(); } } catch (Exception e) { logger.Error("An error occurred while SavePetPreferences. Error: " + e); } finally { _db.Dispose(); } return(RedirectToAction("UserProfile", "Account")); }
public ActionResult PetPreferences() { var model = new PetPreferencesModel(); var _db = new SquareDanceDb(); try { var userId = User.Identity.GetUserId(); var petPreferences = _db.ServiceAndRate.Find(userId); if (petPreferences != null) { model = new PetPreferencesModel(petPreferences); } } catch (Exception e) { logger.Error("An error occurred while PetPreferences. Error: " + e); } finally { _db.Dispose(); } return(View(model)); }
public ActionResult SaveDetails(SitterProfileModel model) { var _db = new SquareDanceDb(); try { var userId = User.Identity.GetUserId(); var details = _db.SitterProfile.Find(userId); if (details != null) { details.LiveCondition = model.LiveCondition; details.AnySmoker = model.AnySmoker; details.HaveChildren = model.HaveChildren; details.HaveCats = model.HaveCats; details.CagedPets = model.CagedPets; details.SittingFurniture = model.SittingFurniture; details.DogExperience = model.DogExperience; details.Describe = model.Describe; details.DogCPR = model.DogCPR; details.OralMedication = model.OralMedication; details.InjectedMedication = model.InjectedMedication; details.SeniorDogExperience = model.SeniorDogExperience; details.ExericiseForHighEnergyDog = model.ExericiseForHighEnergyDog; _db.SaveChanges(); } } catch (Exception e) { logger.Error("An error occurred while SaveDetails. Error: " + e); } finally { _db.Dispose(); } return(RedirectToAction("PetPreferences", "Account")); }