예제 #1
0
        public ActionResult UpdateTestimonial(TestimonialEditFormViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View("TestimonialEditForm", viewModel));
            }
            if (viewModel.ProfilePicture != null)
            {
                string fileName  = Path.GetFileNameWithoutExtension(viewModel.ProfilePicture.FileName);
                string extension = Path.GetExtension(viewModel.ProfilePicture.FileName);
                fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension;
                viewModel.Testimonial.ProfileImagePath = "~/Images/" + fileName;
                fileName = Path.Combine(Server.MapPath("~/Images"), fileName);
                viewModel.ProfilePicture.SaveAs(fileName);
            }

            var testimonialInDb = _context.Testimonials.SingleOrDefault(t => t.Id == viewModel.Testimonial.Id);

            if (testimonialInDb != null)
            {
                testimonialInDb.Name             = viewModel.Testimonial.Name;
                testimonialInDb.Designation      = viewModel.Testimonial.Designation;
                testimonialInDb.Message          = viewModel.Testimonial.Message;
                testimonialInDb.ProfileImagePath = viewModel.Testimonial.ProfileImagePath;
                _context.SaveChanges();
            }
            return(RedirectToAction("Testimonials", "Admin"));
        }
예제 #2
0
        public ActionResult EditTestimonials(int id)
        {
            var viewModel = new TestimonialEditFormViewModel
            {
                Testimonial = _context.Testimonials.SingleOrDefault(t => t.Id == id)
            };

            return(View("TestimonialEditForm", viewModel));
        }