public static List<TestimonialModel> GetAll()
        {
            List<TestimonialModel> testimonialList = new List<TestimonialModel>();
            string testimonialFileName = "testimonials.xml";
            string testimonialFilePath = HttpContext.Current.Server.MapPath(Path.Combine("~/App_Data", testimonialFileName));

            XElement xElement = XElement.Load(testimonialFilePath);
            IEnumerable<XElement> allTestimonials = xElement.Elements();
            IEnumerable<XElement> visibleTestimonials = from t in allTestimonials
                                                        where t.Attribute("IsVisible").Value == "true"
                                                        select t;

            foreach (XElement visibleTestimonial in visibleTestimonials)
            {
                TestimonialModel testimonial = new TestimonialModel();

                testimonial.Name = visibleTestimonial.Element("Name").Value;
                testimonial.Email = visibleTestimonial.Element("Email").Value;
                testimonial.Country = visibleTestimonial.Element("Country").Value;
                testimonial.Message = visibleTestimonial.Element("Message").Value;
                testimonial.CreatedDate = DateTime.Parse(visibleTestimonial.Attribute("CreatedDate").Value);
                testimonialList.Add(testimonial);

            }

            return testimonialList;
        }
        public ActionResult Testimonials(TestimonialModel model)
        {
            if (!ModelState.IsValid)
                return View(model);
            model.IsVisible = true;
            model.CreatedDate = DateTime.UtcNow;
            TestimonialModel testimonial = CommonRepository.Add(model);

            TempData["status"] = testimonial != null ? true : false;

            return RedirectToAction("Testimonials");
        }
 internal static TestimonialModel Add(TestimonialModel testimonial)
 {
     WriteToXml(testimonial);
     return testimonial;
 }
        private static void WriteToXml(TestimonialModel testimonial)
        {
            string testimonialFileName = "testimonials.xml";
            string testimonialFilePath = HttpContext.Current.Server.MapPath(Path.Combine("~/App_Data", testimonialFileName));

            XElement xElement = XElement.Load(testimonialFilePath);
            xElement.Add(new XElement("Testimonial",
                new XAttribute("IsVisible", testimonial.IsVisible),
                new XAttribute("CreatedDate", testimonial.CreatedDate.ToString("dd-MM-yyyy")),
                new XElement("Name", testimonial.Name),
                new XElement("Email", testimonial.Email),
                new XElement("Country", testimonial.Country),
                new XElement("Message", testimonial.Message)));

            xElement.Save(testimonialFilePath);
        }