Пример #1
0
        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));
        }
Пример #2
0
        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));
        }
Пример #3
0
        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));
        }
Пример #4
0
        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();
            }
        }
Пример #5
0
        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"));
        }
Пример #6
0
        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();
            }
        }
Пример #7
0
        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));
        }
Пример #8
0
        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 }));
        }
Пример #9
0
        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"));
        }
Пример #10
0
        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"));
        }