예제 #1
0
 public ActionResult Update()
 {
     using (var context = new ContentStorage())
     {
         var contactsInfo = context.Content.Select(c => c).Where(c => c.IsContactsPage).First();
         return View(contactsInfo);
     }
 }
예제 #2
0
 public ActionResult Details(string id)
 {
     using (var context = new ContentStorage())
     {
         var excursion = context.Excursion.Include("Comments").Select(e => e).Where(e => e.Name == id).First();
         return View(excursion);
     }
 }
예제 #3
0
        //
        // GET: /Contacts/

        public ActionResult Index(string message)
        {
            using (var context = new ContentStorage())
            {
                var contactsInfo = context.Content.Select(c => c).Where(c => c.IsContactsPage).First();
                ViewData["message"] = message;
                return View(contactsInfo);
            }
        }
예제 #4
0
 public ActionResult Index(ExcursionType type)
 {
     ViewData["ExcursionType"] = type;
     var exType = (int) type;
     using (var context = new ContentStorage())
     {
         var excursionList = context.Excursion.Where(e => e.ExcursionType == exType || exType == 0).Select(e => e).OrderBy(e => e.SortOrder).ToList();
         return View(excursionList);
     }
 }
예제 #5
0
 public ActionResult Delete(int id)
 {
     using (var context = new ContentStorage())
     {
         var content = context.Content.Select(c => c).Where(c => c.Id == id).First();
         context.DeleteObject(content);
         context.SaveChanges();
     }
     return RedirectToAction("Index", "Excursions", new { area = "" });
 }
예제 #6
0
        //
        // GET: /Admin/Comments/

        public ActionResult Delete(int id, string excursionId)
        {

            using (var context = new ContentStorage())
            {
                var comment = context.Comments.Select(c => c).Where(c => c.Id == id).First();
                context.DeleteObject(comment);
                context.SaveChanges();
            }

            return RedirectToAction("Details", "Excursions", new { area = "", id = excursionId });
        }
예제 #7
0
        //
        // GET: /Content/

        public ActionResult Index(string id)
        {
            using (var context = new ContentStorage())
            {
                var content = context.Content.Select(c => c).Where(c => c.ContentId == id).FirstOrDefault();
                if (content == null)
                {
                    return RedirectToAction("NotFound", "Errors");
                }
                return View("Content", content);
            }
        }
예제 #8
0
 public ActionResult AddEdit(int? id)
 {
     Excursion excursion = null;
     if (id.HasValue)
     {
         using (var context = new ContentStorage())
         {
             excursion = context.Excursion.Select(c => c).Where(c => c.Id == id).First();
         }
     }
     else
     {
         excursion = new Excursion();
     }
     return View(excursion);
 }
예제 #9
0
 public ActionResult AddEdit(int? id)
 {
     Content content;
     if (id.HasValue)
     {
         using (var context = new ContentStorage())
         {
             content = context.Content.Select(c => c).Where(c => c.Id == id).First();
         }
     }
     else
     {
         content = new Content();
     }
     return View(content);
 }
예제 #10
0
        public void AddComment(AddCommentFormModel addCommentFormModel, int excursionId)
        {
            using (var context = new ContentStorage())
            {



                Excursion excursion = context.Excursion.Select(e => e).Where(e => e.Id == excursionId).First();

                var comment = new Comments
                                  {
                                      Excursion = excursion,
                                      Text = HttpUtility.HtmlDecode(addCommentFormModel.Text),
                                      Author = addCommentFormModel.Name,
                                      Date = DateTime.Now
                                  };
                context.AddToComments(comment);
                context.SaveChanges();

                string linkBase = ConfigurationManager.AppSettings["linkBase"];
                string emailFrom = ConfigurationManager.AppSettings["emailFrom"];
                string emailsTo = ApplicationData.NewCommentNotificationEmail;
                const string subject = "walking.kiev.ua - Новый комментарий";
                string[] replacements = {
                                                linkBase + "/Excursions/" + excursion.Name, comment.Date.ToString()
                                                ,
                                                comment.Author, comment.Text
                                            };

                MailHelper.SendTemplate(emailFrom, emailsTo, subject, "newComment", false, replacements);




                //Response.Write("<script>window.top.$.fancybox.close()</script>");
                Response.Write("<script>window.top.location.href=window.top.location.href</script>");

                //Redirect("~/Excursions/Details/" + excursion.Name);

                //return RedirectToAction("Details", "Excursions", new { area = "", id = excursion.Name });



                //return RedirectToAction("Details", "Excursions", new { area = "", id = excursion.Name });
            }

        }
예제 #11
0
        public ActionResult AddEdit(Content content, int? Id)
        {

            if (String.IsNullOrEmpty(content.Title))
                ModelState.AddModelError("Title", "Title is required!");
            if (String.IsNullOrEmpty(content.Text))
                ModelState.AddModelError("Text", "Text is required!");
            if (String.IsNullOrEmpty(content.ContentId))
                ModelState.AddModelError("ContentId", "ContentId is required!");


            content.Text = HttpUtility.HtmlDecode(content.Text);

            if (ModelState.IsValid)
            {
                
                using (var context = new ContentStorage())
                {
                    if (Id.HasValue && Id.Value > 0)
                    {
                        content.Id = Id.Value;
                        object originalItem;
                        EntityKey entityKey = new EntityKey("ContentStorage.Content", "Id", content.Id);
                        if (context.TryGetObjectByKey(entityKey, out originalItem))
                        {
                            context.ApplyPropertyChanges(entityKey.EntitySetName, content);
                        }
                    }
                    else
                    {
                        context.AddToContent(content);
                    }
                    context.SaveChanges();
                }
                return RedirectToAction("Index", "Content", new {area = "", id = content.ContentId});
            }
            return View(content);
        }
예제 #12
0
        public ActionResult Update(Content content)
        {
            using (var context = new ContentStorage())
            {
                var contactsInfo = context.Content.Select(c => c).Where(c => c.IsContactsPage).First();

                content.Id = contactsInfo.Id;
                content.Text = HttpUtility.HtmlDecode(content.Text);
                content.IsContactsPage = true;

                content.ContentId = "Contacts";
                content.Title = "Контакты";

                object originalItem;
                EntityKey entityKey = new EntityKey("ContentStorage.Content", "Id", content.Id);
                if (context.TryGetObjectByKey(entityKey, out originalItem))
                {
                    context.ApplyPropertyChanges(entityKey.EntitySetName, content);
                }
                context.SaveChanges();
            }
            return RedirectToAction("Index", "Contacts", new { area = "" });
        }
예제 #13
0
        public ActionResult AddEdit(FormCollection form, int? Id)
        {
            using (var context = new ContentStorage())
            {
                Excursion excursion;

                if (Id.HasValue && Id.Value > 0)
                {
                    excursion = context.Excursion.Select(e => e).Where(e => e.Id == Id).First();
                }
                else
                {
                    excursion = new Excursion();
                }


                string[] fieldsToUpdate;
                string file = Request.Files["image"].FileName;
                if (!string.IsNullOrEmpty(file))
                {

                    if(!string.IsNullOrEmpty(excursion.ImageSource))
                    {
                        IOHelper.DeleteFile("~/Content/Images", excursion.ImageSource);
                    }

                    string newFileName = IOHelper.GetUniqueFileName("~/Content/Images", file);
                    string filePath = Path.Combine(Server.MapPath("~/Content/Images"), newFileName);
                    Request.Files["image"].SaveAs(filePath);
                    excursion.ImageSource = newFileName;
                    fieldsToUpdate = new string[] { "Title", "ShortDescription", "Text", "Name", "Keywords", "Description", "Price", "SortOrder", "Popular", "ImageSource" };
                }
                else
                {
                    fieldsToUpdate = new string[] { "Title", "ShortDescription", "Text", "Name", "Keywords", "Description", "Price", "SortOrder", "Popular", "ExcursionType" };
                }

                excursion.ExcursionType = Convert.ToInt32(form["excursionType"]);

                TryUpdateModel(excursion, fieldsToUpdate, form.ToValueProvider());


                if (String.IsNullOrEmpty(excursion.Title))
                    ModelState.AddModelError("Title", "Title is required!");
                if (String.IsNullOrEmpty(excursion.ShortDescription))
                    ModelState.AddModelError("ShortDescription", "ShortDescription is required!");
                if (String.IsNullOrEmpty(excursion.Text))
                    ModelState.AddModelError("Text", "Text is required!");
                if (String.IsNullOrEmpty(excursion.Name))
                    ModelState.AddModelError("Name", "Name is required!");


                

                if (ModelState.IsValid)
                {
                    

                    excursion.Text = HttpUtility.HtmlDecode(excursion.Text);
                    excursion.ShortDescription = HttpUtility.HtmlDecode(excursion.ShortDescription);

                    if (excursion.Id == 0)
                        context.AddToExcursion(excursion);

                    context.SaveChanges();
                    return RedirectToAction("Index", "Excursions", new { area = "" });
                }
                return View(excursion);
            }
        }
예제 #14
0
 public ActionResult Delete(int id)
 {
     using (var context = new ContentStorage())
     {
         Excursion excursion = context.Excursion.Select(e => e).Where(e => e.Id == id).First();
         if (!string.IsNullOrEmpty(excursion.ImageSource))
         {
             IOHelper.DeleteFile("~/Content/Images", excursion.ImageSource);
         }
         context.DeleteObject(excursion);
         context.SaveChanges();
     }
     return RedirectToAction("Index", "Excursions", new { area = "" });
 }