public ActionResult Create([Bind(Include = "Age,ImagePath,BreedType,PetName,Price,PetType")] PetDetailsViewModel petdetails, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                if (file != null)
                {
                    file.SaveAs(HttpContext.Server.MapPath("~/Images/") + file.FileName);
                    var           filepath = HttpContext.Server.MapPath("~/Images/") + file.FileName;
                    PetDetailsDto pet      = new PetDetailsDto
                    {
                        Age       = petdetails.Age,
                        ImagePath = file.FileName,
                        BreedType = petdetails.BreedType,
                        PetName   = petdetails.PetName,
                        Price     = petdetails.Price,
                        PetType   = petdetails.PetType
                    };

                    transRepos.Save(pet);
                }
            }
            var xx      = GetPetType();
            var petType = new SelectList(xx, "TypeId", "PetType");

            ViewData["pettype"] = petType;
            return(View(petdetails));
        }
        public ActionResult Edit(PetDetailsViewModel petdetails, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                if (file != null)
                {
                    file.SaveAs(HttpContext.Server.MapPath("~/Images/") + file.FileName);
                    var filepath = HttpContext.Server.MapPath("~/Images/") + file.FileName;

                    PetDetailsDto pet = new PetDetailsDto
                    {
                        Age       = petdetails.Age,
                        ImagePath = file.FileName,
                        BreedType = petdetails.BreedType,
                        PetName   = petdetails.PetName,
                        Price     = petdetails.Price,
                        PetType   = petdetails.PetType
                    };
                    transRepos.EditPet(pet, petId);
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ModelState.AddModelError("ImagePath", "Please select a file");
                    return(RedirectToAction("Edit", "PetDetails", new { id = petId }));
                }
            }
            var xx      = GetPetType();
            var petType = new SelectList(xx, "TypeId", "PetType", petdetails.PetType);

            ViewData["pettype"] = petType;
            return(View(petdetails));
        }
Exemplo n.º 3
0
        public void Save(PetDetailsDto pet)
        {
            PetDetails pett = new PetDetails
            {
                Age       = pet.Age,
                ImagePath = pet.ImagePath,
                BreedType = pet.BreedType,
                PetName   = pet.PetName,
                Price     = pet.Price,
                TypeId    = Convert.ToInt32(pet.PetType)
            };

            transRepos.SaveDetails(pett);
        }
Exemplo n.º 4
0
        /// <summary>
        /// To convert to dto
        /// </summary>
        /// <param name="petdetails"></param>
        /// <param name="file"></param>
        /// <returns></returns>
        PetDetailsDto ConvertToDto(PetDetailsViewModel petdetails, HttpPostedFileBase file)
        {
            PetDetailsDto pet = new PetDetailsDto
            {
                Age       = petdetails.Age,
                ImagePath = file.FileName,
                BreedType = petdetails.BreedType,
                PetName   = petdetails.PetName,
                Price     = petdetails.Price,
                PetType   = petdetails.PetType,
                Gender    = petdetails.Gender
            };

            return(pet);
        }
Exemplo n.º 5
0
        public PetDetailsDto GetPetById(int id)
        {
            PetDetails    petdetails = transRepos.GetPetById(id);
            PetDetailsDto pett       = new PetDetailsDto
            {
                Age       = petdetails.Age,
                ImagePath = petdetails.ImagePath,
                BreedType = petdetails.BreedType,
                PetName   = petdetails.PetName,
                Price     = petdetails.Price,
                PetType   = petdetails.pet.PetType
            };

            return(pett);
        }
Exemplo n.º 6
0
        public void EditPet(PetDetailsDto pd, int petId)
        {
            PetDetails pett = new PetDetails
            {
                Age       = pd.Age,
                PetId     = petId,
                ImagePath = pd.ImagePath,
                BreedType = pd.BreedType,
                PetName   = pd.PetName,
                Price     = pd.Price,
                TypeId    = Convert.ToInt32(pd.PetType)
            };

            transRepos.EditPet(pett);
        }
        public PetDetailsViewModel GetPetById(int id)
        {
            PetDetailsDto       pet = transRepos.GetPetById(id);
            PetDetailsViewModel pt  = new PetDetailsViewModel
            {
                Age       = pet.Age,
                BreedType = pet.BreedType,
                PetName   = pet.PetName,
                ImagePath = pet.ImagePath,
                Price     = pet.Price,
                PetType   = pet.PetType
            };

            return(pt);
        }
Exemplo n.º 8
0
        public void Save(PetDetailsDto pet)
        {
            PetDetails pett = new PetDetails
            {
                Age       = pet.Age,
                ImagePath = pet.ImagePath,
                BreedType = pet.BreedType,
                PetName   = pet.PetName,
                Price     = pet.Price,
                TypeId    = Convert.ToInt32(pet.PetType),
                Gender    = pet.Gender
            };

            petRepository.SaveDetails(pett);
        }
Exemplo n.º 9
0
        /// <summary>
        /// To get pet by their id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public PetDetailsViewModel GetPetById(int id)
        {
            PetDetailsDto       pet     = petService.GetPetById(id);
            PetDetailsViewModel petView = new PetDetailsViewModel
            {
                Age       = pet.Age,
                BreedType = pet.BreedType,
                PetName   = pet.PetName,
                ImagePath = pet.ImagePath,
                Price     = pet.Price,
                PetType   = pet.PetType,
                Gender    = pet.Gender
            };

            return(petView);
        }
Exemplo n.º 10
0
        public ActionResult Edit(PetDetailsViewModel petdetails, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                if (file != null)
                {
                    file.SaveAs(HttpContext.Server.MapPath("~/Images/") + file.FileName);
                    var           filePath = HttpContext.Server.MapPath("~/Images/") + file.FileName;
                    PetDetailsDto pet      = new PetDetailsDto
                    {
                        Age       = petdetails.Age,
                        ImagePath = file.FileName,
                        BreedType = petdetails.BreedType,
                        PetName   = petdetails.PetName,
                        Price     = petdetails.Price,
                        PetType   = petdetails.PetType,
                        Gender    = petdetails.Gender
                    };
                    petService.EditPet(pet, petId);
                    return(RedirectToAction("Index"));
                }
                else if (file == null)
                {
                    PetDetailsDto pet = new PetDetailsDto
                    {
                        Age       = petdetails.Age,
                        ImagePath = imagepath,
                        BreedType = petdetails.BreedType,
                        PetName   = petdetails.PetName,
                        Price     = petdetails.Price,
                        PetType   = petdetails.PetType,
                        Gender    = petdetails.Gender
                    };
                    petService.EditPet(pet, petId);
                    return(RedirectToAction("Index"));
                }
            }
            var type    = GetPetType();
            var petType = new SelectList(type, "TypeId", "PetType", petdetails.PetType);

            ViewData["pettype"]  = petType;
            petdetails.ImagePath = imagepath;
            return(View(petdetails));
        }
Exemplo n.º 11
0
        public ActionResult Create([Bind(Include = "Age,ImagePath,BreedType,PetName,Price,PetType,Gender")] PetDetailsViewModel petdetails, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                if (file != null)
                {
                    file.SaveAs(HttpContext.Server.MapPath("~/Images/") + file.FileName);
                    var filepath          = HttpContext.Server.MapPath("~/Images/") + file.FileName;
                    var allowedExtensions = new[] { ".jpg", ".jpeg", ".png", ".JPG", ".JPEG" };
                    var checkextension    = Path.GetExtension(file.FileName).ToLower();
                    if (!allowedExtensions.Contains(checkextension))
                    {
                        ViewBag.ErrorMessage = "Select jpeg or png Image with height and width less than 600";
                    }
                    else
                    {
                        using (System.Drawing.Image image = System.Drawing.Image.FromStream(file.InputStream, true, true))
                        {
                            if (image.Width <= 600 && image.Height <= 600)
                            {
                                PetDetailsDto pett = ConvertToDto(petdetails, file);
                                petService.Save(pett);
                                return(RedirectToAction("Index"));
                            }
                        }
                    }
                }
                else
                {
                    ViewBag.ErrorMessage = "Please Select jpeg or png Image with height and width less than 600";
                    return(View(petdetails));
                }
            }
            var pet     = GetPetType();
            var petType = new SelectList(pet, "TypeId", "PetType");

            ViewData["pettype"] = petType;
            return(View(petdetails));
        }