public ActionResult Create(CreateAdoptionFormViewModel model, int id)
        {
            if (model != null && ModelState.IsValid)
            {
                model.AnimalsDescription = this.sanitizeService.Sanitize(model.AnimalsDescription);

                model.ExpirienceWithAnimals = this.sanitizeService.Sanitize(model.ExpirienceWithAnimals);

                model.KidsDescription = this.sanitizeService.Sanitize(model.KidsDescription);

                model.Address = this.sanitizeService.Sanitize(model.Address);

                model.AttitudeAboutCastration = this.sanitizeService.Sanitize(model.AttitudeAboutCastration);

                var newAdoptionForm = AutoMapper.Mapper.Map<AdoptionForm>(model);

                newAdoptionForm.AnimalId = id;

                newAdoptionForm.Animal = animals.GetById(id).FirstOrDefault();

                newAdoptionForm.UserId = this.User.Identity.GetUserId();

                newAdoptionForm.User = adopters.GetById(newAdoptionForm.UserId).FirstOrDefault();

                this.adoptionForms.AddNew(newAdoptionForm);

                return this.RedirectToAction("Index", "Home", new { area = "" });
            }
            else
            {
                return this.View(model);
            }
        }
示例#2
0
        public ActionResult Create(CreateAdoptionFormViewModel model, int id)
        {
            if (model != null && ModelState.IsValid)
            {
                model.AnimalsDescription = this.sanitizeService.Sanitize(model.AnimalsDescription);

                model.ExpirienceWithAnimals = this.sanitizeService.Sanitize(model.ExpirienceWithAnimals);

                model.KidsDescription = this.sanitizeService.Sanitize(model.KidsDescription);

                model.Address = this.sanitizeService.Sanitize(model.Address);

                model.AttitudeAboutCastration = this.sanitizeService.Sanitize(model.AttitudeAboutCastration);

                var newAdoptionForm = AutoMapper.Mapper.Map <AdoptionForm>(model);

                newAdoptionForm.AnimalId = id;

                newAdoptionForm.Animal = animals.GetById(id).FirstOrDefault();

                newAdoptionForm.UserId = this.User.Identity.GetUserId();

                newAdoptionForm.User = adopters.GetById(newAdoptionForm.UserId).FirstOrDefault();

                this.adoptionForms.AddNew(newAdoptionForm);

                return(this.RedirectToAction("Index", "Home", new { area = "" }));
            }
            else
            {
                return(this.View(model));
            }
        }