Example #1
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 = "" });
 }
Example #2
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 });
        }
Example #3
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 });
            }

        }
Example #4
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);
        }
Example #5
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 = "" });
        }
Example #6
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);
            }
        }
Example #7
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 = "" });
 }