Пример #1
0
 public ActionResult Create(FormCollection form, HttpPostedFileBase fileUpload, Project model)
 {
     try
     {
         using (var context = new SiteContainer())
         {
             var content = context.Content.First(c => c.Id == model.ContentId);
             var project = new Project();
             TryUpdateModel(project, new[] { "Name", "Title", "DescriptionTitle", "SortOrder" });
             project.Description = HttpUtility.HtmlDecode(form["Description"]);
             project.VideoSource = form["VideoSource"];
             if (fileUpload != null)
             {
                 string fileName = IOHelper.GetUniqueFileName("~/Content/Images", fileUpload.FileName);
                 string filePath = Server.MapPath("~/Content/Images");
                 filePath = Path.Combine(filePath, fileName);
                 fileUpload.SaveAs(filePath);
                 project.ImageSource = fileName;
             }
             content.Projects.Add(project);
             //context.AddToProject(project);
             context.SaveChanges();
             return RedirectToAction("Projects", "Home", new { area = "", id = project.Name });
         }
     }
     catch
     {
         return View();
     }
 }
Пример #2
0
        public ProjectModel(SiteContainer context, string id, string contentId=null)
            : base(context)
        {
            ContentId = contentId;
            if (!string.IsNullOrEmpty(id))
            {
                Project = context.Project
                    .Include("ProjectImages")
                    //.Include("Songs")
                    //.Include("FlashContents")
                    .FirstOrDefault(p => p.Name == id);

                

                if (Project == null)
                {
                    throw new HttpNotFoundException(string.Format("Project with key {0}", id));
                }
                
                Project.Songs.Load();
                Project.FlashContents.Load();
                foreach (var flashContent in Project.FlashContents)
                {
                    flashContent.DirectoryName = flashContent.ImageSource;
                    flashContent.ImageSource = flashContent.ImageSource + ".html";
                }
            }

        }
Пример #3
0
        public ActionResult EditFlash(FlashContent model,HttpPostedFileBase fileUploadPreview)
        {
            using (var context = new SiteContainer())
            {
                var flashContent = context.FlashContent.Include("Project").First(f => f.Id == model.Id);
                var project = flashContent.Project;
                ViewBag.projectId = project.Id;
                ViewBag.projectName = project.Name;
                //TryUpdateModel(flashContent, new[] {"Title"});
                if (fileUploadPreview != null)
                {

                    var file = fileUploadPreview;

                    var fileName = IOHelper.GetUniqueFileName("~/Content/Images", file.FileName);
                    var filePath = Server.MapPath("~/Content/Images");
                    filePath = Path.Combine(filePath, fileName);
                    file.SaveAs(filePath);
                    flashContent.ImageSourcePreview = fileName;
                    flashContent.Title = model.Title ?? "";
                    context.SaveChanges();
                }
                else
                {
                    ViewBag.Errormessage = "Выберите файлы для загрузки!";
                    return View();
                }

                context.SaveChanges();
                return RedirectToAction("Projects", "Home", new { area = "", id = project.Name });
            }
        }
Пример #4
0
 public ActionResult Music(string filename)
 {
     using (var context = new SiteContainer())
     {
         return View(context.MusicItem.ToList());
     }
 }
Пример #5
0
 public ActionResult Index()
 {
     using (var context = new SiteContainer())
     {
         var backgrounds = context.MusicItem.ToList();
         return View(backgrounds);
     }
 }
Пример #6
0
 public ActionResult Edit(int id)
 {
     using (var context = new SiteContainer())
     {
         var project = context.Project.First(p => p.Id == id);
         return View(project);
     }
 }
Пример #7
0
        //
        // GET: /Admin/Content/Edit/5
 
        public ActionResult Edit(int id)
        {
            using (var context = new SiteContainer())
            {
                var content = context.Content.First(c => c.Id == id);

                return View(content);
            }
        }
Пример #8
0
 public ActionResult ProjectDetails(string id)
 {
     using (var context = new SiteContainer())
     {
         var model = new ProjectModel(context, id);
         ViewBag.SiteBgFileName = model.RandomSiteBgFileName;
         return View(model.Project);
     }
 }
Пример #9
0
 public ActionResult Create(int id)
 {
     using (var context = new SiteContainer())
     {
         var content = context.Content.First(c => c.Id == id);
         var projects = content.Projects.ToList();
         var sortOrder = projects.Any() ? projects.Max(p => p.SortOrder) : 0;
         return View(new Project { SortOrder = sortOrder + 1, Content = content });
     }
 }
Пример #10
0
 public ActionResult Index()
 {
     using (var context = new SiteContainer())
     {
         var model = new SiteModel(context);
         this.SetSeoContent(model);
         ViewBag.SiteBgFileName = model.RandomSiteBgFileName;
         return View(model);
     }
 }
Пример #11
0
 public ActionResult EditFlash(int id)
 {
     using (var context = new SiteContainer())
     {
         var flashContent = context.FlashContent.First(f => f.Id == id);
         var project = flashContent.Project;
         ViewBag.projectId = project.Id;
         ViewBag.projectName = project.Name;
         return View(flashContent);
     }
 }
Пример #12
0
 public ActionResult Delete(int id)
 {
     using (var context = new SiteContainer())
     {
         var projectImage = context.MusicItem.First(pi => pi.Id == id);
         IOHelper.DeleteFile("~/Content/Music/mp3", projectImage.FileName);
         context.DeleteObject(projectImage);
         context.SaveChanges();
         return RedirectToAction("Index");
     }
 }
Пример #13
0
 public ActionResult Delete(int id)
 {
     using (var context = new SiteContainer())
     {
         var projectImage = context.SiteBackground.First(pi => pi.Id == id);
         IOHelper.DeleteFile("~/Content/Images", projectImage.ImageSource);
         foreach (var thumbnail in SiteSettings.Thumbnails)
         {
             IOHelper.DeleteFile("~/ImageCache/" + thumbnail.Key, projectImage.ImageSource);
         }
         context.DeleteObject(projectImage);
         context.SaveChanges();
         return RedirectToAction("Index");
     }
 }
Пример #14
0
        //public IEnumerable<Project> Projects { get; set; }

        public SiteModel(SiteContainer context)
        {
            Title = "FILIMONOV INTERIOR LAB";
            Contents = context.Content.Include("Projects").ToList();

            //Projects = context.Project.ToList();

            SeoDescription = Contents.First().SeoDescription;
            SeoKeywords = Contents.First().SeoKeywords;

            var allBackgrounds = context.SiteBackground.ToList();
            var sitebg = allBackgrounds.OrderBy(s => Guid.NewGuid()).Take(1).FirstOrDefault();
            if (sitebg != null)
            {
                RandomSiteBgFileName = sitebg.ImageSource;
            }


        }
Пример #15
0
 public ActionResult Create(MusicItem model, HttpPostedFileBase fileUpload)
 {
     using (var context = new SiteContainer())
     {
         var file = fileUpload;
         if (file != null)
         {
             var pi = new MusicItem();
             string fileName = IOHelper.GetUniqueFileName("~/Content/Music/mp3", file.FileName);
             string filePath = Server.MapPath("~/Content/Music/mp3");
             filePath = Path.Combine(filePath, fileName);
             file.SaveAs(filePath);
             pi.FileName = fileName;
             context.AddToMusicItem(pi);
             context.SaveChanges();
         }
         return RedirectToAction("Index");
     }
 }
Пример #16
0
 public ActionResult Edit(int id, FormCollection form)
 {
     try
     {
         using (var context = new SiteContainer())
         {
             var content = context.Content.First(c => c.Id == id);
             TryUpdateModel(content, new[] { "Title", "SeoDescription", "SeoKeywords","SortOrder" });
             content.Text = HttpUtility.HtmlDecode(form["Text"]);
             if (content.ContentType != (int) ContentType.Feedback)
                 content.ContentType = form["isProject"] == "on" ? 1 : 0;
             context.SaveChanges();
             return RedirectToAction("Index", "Home", new { area = "" });
         }
     }
     catch
     {
         return View();
     }
 }
Пример #17
0
 public ActionResult Create(FormCollection form)
 {
     try
     {
         using (var context  = new SiteContainer())
         {
             var content = new Content();
             TryUpdateModel(content, new[] { "Title", "SeoDescription", "SeoKeywords","SortOrder" });
             content.Text = HttpUtility.HtmlDecode(form["Text"]);
             content.ContentType = form["isProject"]=="on" ? 1 : 0;
             context.AddToContent(content);
             context.SaveChanges();
             return RedirectToAction("Index", "Home", new {area = ""});
         }
     }
     catch
     {
         return View();
     }
 }
Пример #18
0
        public ActionResult Create(SiteBackground model)
        {
            using (var context = new SiteContainer())
            {
                for (int i = 0; i < Request.Files.Count; i++)
                {
                    var file = Request.Files[i];
                    if (file == null) continue;

                    var pi = new SiteBackground();
                    string fileName = IOHelper.GetUniqueFileName("~/Content/Images", file.FileName);
                    string filePath = Server.MapPath("~/Content/Images");
                    filePath = Path.Combine(filePath, fileName);
                    file.SaveAs(filePath);
                    pi.ImageSource = fileName;
                    context.AddToSiteBackground(pi);
                    context.SaveChanges();
                }
                return RedirectToAction("Index");
            }
        }
Пример #19
0
        public ActionResult AddSongToProject(int id)
        {
            using (var context = new SiteContainer())
            {
                var project = context.Project.First(p => p.Id == id);

                ViewBag.projectId = project.Id;
                ViewBag.projectName = project.Name;
            }
            return View();
        }
Пример #20
0
        //
        // GET: /Admin/Content/Delete/5
 
        public ActionResult Delete(int id)
        {
            using (var context = new SiteContainer())
            {
                var content = context.Content.Include("Projects").First(c => c.Id == id);
                if (content.Projects.Any())
                {
                    TempData["error"] = "Невозможно удалить раздел, в котором есть проекты. Сначала удалите все проекты из раздела.";
                    return RedirectToAction("Index", "Home", new { area = "" });
                }
                else
                {
                    context.DeleteObject(content);
                    context.SaveChanges();
                }
                return RedirectToAction("Index", "Home", new { area = "" });
            }
        }
Пример #21
0
        public ActionResult Edit(int id, FormCollection form, HttpPostedFileBase fileUpload)
        {
            try
            {
                using (var context = new SiteContainer())
                {
                    var project = context.Project.First(p => p.Id == id);
                    TryUpdateModel(project, new[] { "Name", "Title", "DescriptionTitle", "SortOrder" });
                    project.Description = HttpUtility.HtmlDecode(form["Description"]);
                    project.VideoSource = form["VideoSource"];
                    if (fileUpload != null)
                    {
                        if (!string.IsNullOrEmpty(project.ImageSource))
                        {

                            IOHelper.DeleteFile("~/Content/Images", project.ImageSource);
                            foreach (var thumbnail in SiteSettings.Thumbnails)
                            {
                                IOHelper.DeleteFile("~/ImageCache/" + thumbnail.Key, project.ImageSource);
                            }
                        }

                        string fileName = IOHelper.GetUniqueFileName("~/Content/Images", fileUpload.FileName);
                        string filePath = Server.MapPath("~/Content/Images");
                        filePath = Path.Combine(filePath, fileName);
                        fileUpload.SaveAs(filePath);
                        project.ImageSource = fileName;
                    }
                    context.SaveChanges();
                    return RedirectToAction("Projects", "Home", new { area = "", id = project.Name });
                }
            }
            catch
            {
                return View();
            }
        }
Пример #22
0
        public ActionResult AddFlashToProject(FlashContent model, int projectId, HttpPostedFileBase fileUpload, HttpPostedFileBase fileUploadPreview)
        {

            using (var context = new SiteContainer())
            {
                var project = context.Project.First(p => p.Id == projectId);
                ViewBag.projectId = project.Id;
                ViewBag.projectName = project.Name;

                try
                {
                    if (fileUpload != null && fileUploadPreview != null)
                    {
                        var file = fileUpload;
                        var pi = new FlashContent();
                        string fileName = IOHelper.GetUploadFileName("~/Content/TmpArchive", file.FileName);
                        string filePath = Server.MapPath("~/Content/TmpArchive");



                        //string flashSourceFilePath = filePath;
                        //string flashDestFilePath = filePath;

                        filePath = Path.Combine(filePath, fileName);
                        file.SaveAs(filePath);

                        string archiveName = Path.GetFileNameWithoutExtension(fileName);

                        string extractedArchivePath = Path.Combine(Server.MapPath("~/Content/FlashContent"), archiveName);

                        Directory.CreateDirectory(extractedArchivePath);

                        using (ZipFile zip = ZipFile.Read(filePath))
                        {
                            foreach (ZipEntry e in zip)
                            {
                                e.Extract(extractedArchivePath, true);  // true => overwrite existing files
                            }
                        }

                        System.IO.File.Delete(filePath);


                        file = fileUploadPreview;

                        fileName = IOHelper.GetUniqueFileName("~/Content/Images", file.FileName);
                        filePath = Server.MapPath("~/Content/Images");
                        filePath = Path.Combine(filePath, fileName);
                        file.SaveAs(filePath);
                        pi.ImageSourcePreview = fileName;

                        pi.ImageSource = archiveName;
                        pi.Title = model.Title??"";
                        project.FlashContents.Add(pi);

                        context.SaveChanges();
                    }
                    else
                    {
                        ViewBag.Errormessage = "Выберите файлы для загрузки!";
                        return View();
                    }

                    return RedirectToAction("Projects", "Home", new { area = "", id = project.Name });
                }
                catch (Exception ex)
                {
                    ViewBag.Errormessage = ex.Message;
                    return View();
                }

                //string filePath = Server.MapPath("~/Content/Flash1/ponedelnik.zip");
                //string destPath = Server.MapPath("~/Content/Flash2");

                //using (ZipFile zip = ZipFile.Read(filePath))
                //{
                //    foreach (ZipEntry e in zip)
                //    {
                //        e.Extract(destPath, true);  // true => overwrite existing files
                //    }
                //}
            }
        }
Пример #23
0
        public ActionResult AddImageToProject1(int projectId)
        {
            using (var context = new SiteContainer())
            {
                var project = context.Project.First(p => p.Id == projectId);

                for (int i = 0; i < Request.Files.Count; i++)
                {
                    var file = Request.Files[i];
                    if (file == null) continue;

                    var pi = new ProjectImage();
                    string fileName = IOHelper.GetUniqueFileName("~/Content/Images", file.FileName);
                    string filePath = Server.MapPath("~/Content/Images");
                    filePath = Path.Combine(filePath, fileName);
                    file.SaveAs(filePath);
                    pi.ImageSource = fileName;
                    project.ProjectImages.Add(pi);
                    context.SaveChanges();
                }



                //if (fileUpload != null)
                //{
                //    var pi = new ProjectImage();
                //    string fileName = IOHelper.GetUniqueFileName("~/Content/Images", fileUpload.FileName);
                //    string filePath = Server.MapPath("~/Content/Images");
                //    filePath = Path.Combine(filePath, fileName);
                //    fileUpload.SaveAs(filePath);
                //    pi.ImageSource = fileName;
                //    project.ProjectImages.Add(pi);
                //    context.SaveChanges();
                //}
                return RedirectToAction("Projects", "Home", new { area = "", id = project.Name });
            }
        }
Пример #24
0
        public ActionResult AddSongToProject(Song model, int projectId, HttpPostedFileBase fileUpload)
        {
            using (var context = new SiteContainer())
            {
                var project = context.Project.First(p => p.Id == projectId);
                var file = fileUpload;
                if (file != null)
                {

                    var pi = new Song();
                    string fileName = IOHelper.GetUniqueFileName("~/Content/Music/mp3", file.FileName);
                    string filePath = Server.MapPath("~/Content/Music/mp3");
                    filePath = Path.Combine(filePath, fileName);
                    file.SaveAs(filePath);
                    pi.FileName = fileName;
                    pi.Title = model.Title;
                    project.Songs.Add(pi);
                    context.SaveChanges();
                }
                return RedirectToAction("Projects", "Home", new { area = "", id = project.Name });
            }
        }
Пример #25
0
 public ActionResult DeleteImage(int id)
 {
     using (var context = new SiteContainer())
     {
         var projectImage = context.ProjectImage.Include("Project").First(pi => pi.Id == id);
         var project = projectImage.Project;
         IOHelper.DeleteFile("~/Content/Images", projectImage.ImageSource);
         foreach (var thumbnail in SiteSettings.Thumbnails)
         {
             IOHelper.DeleteFile("~/ImageCache/" + thumbnail.Key, projectImage.ImageSource);
         }
         context.DeleteObject(projectImage);
         context.SaveChanges();
         return RedirectToAction("Projects", "Home", new { area = "", id = project.Name });
     }
 }
Пример #26
0
        public ActionResult Delete(int id)
        {
            using (var context = new SiteContainer())
            {
                var project = context.Project.Include("ProjectImages").First(p => p.Id == id);

                while (project.ProjectImages.Any())
                {
                    var projectImage = project.ProjectImages.First();
                    IOHelper.DeleteFile("~/Content/Images", projectImage.ImageSource);
                    foreach (var thumbnail in SiteSettings.Thumbnails)
                    {
                        IOHelper.DeleteFile("~/ImageCache/" + thumbnail.Key, projectImage.ImageSource);
                    }

                    context.DeleteObject(projectImage);
                }

                while (project.FlashContents.Any())
                {
                    var projectImage = project.FlashContents.First();
                    //IOHelper.DeleteFile("~/Content/Flash", projectImage.ImageSource);
                    //IOHelper.DeleteFile("~/Content/Flash", projectImage.ImageSource, "xml");
                    IOHelper.DeleteDirectory("~/Content/FlashContent", projectImage.ImageSource);
                    IOHelper.DeleteFile("~/Content/Images", projectImage.ImageSourcePreview);

                    context.DeleteObject(projectImage);
                }


                if (project.ImageSource != null)
                {
                    IOHelper.DeleteFile("~/Content/Images", project.ImageSource);
                    foreach (var thumbnail in SiteSettings.Thumbnails)
                    {
                        IOHelper.DeleteFile("~/ImageCache/" + thumbnail.Key, project.ImageSource);
                    }
                }

                while (project.Songs.Any())
                {
                    var projectSong = project.Songs.First();
                    context.DeleteObject(projectSong);
                }

                context.DeleteObject(project);
                context.SaveChanges();

                return RedirectToAction("Projects", "Home", new { area = "" });
            }
        }
Пример #27
0
 public ActionResult DeleteSong(int id)
 {
     using (var context = new SiteContainer())
     {
         var projectImage = context.Song.Include("Project").First(pi => pi.Id == id);
         var project = projectImage.Project;
         IOHelper.DeleteFile("~/Content/Music/mp3", projectImage.FileName);
         context.DeleteObject(projectImage);
         context.SaveChanges();
         return RedirectToAction("Projects", "Home", new { area = "", id = project.Name });
     }
 }
Пример #28
0
        //public ActionResult DeleteFlash(int id)
        //{
        //    using (var context = new SiteContainer())
        //    {
        //        var projectImage = context.FlashContent.Include("Project").First(pi => pi.Id == id);
        //        var project = projectImage.Project;
        //        IOHelper.DeleteFile("~/Content/Flash", projectImage.ImageSource);
        //        IOHelper.DeleteFile("~/Content/Flash", projectImage.ImageSource, "xml");
        //        context.DeleteObject(projectImage);
        //        context.SaveChanges();
        //        return RedirectToAction("Projects", "Home", new { area = "", id = project.Name });
        //    }
        //}

        public ActionResult DeleteFlash(int id)
        {
            using (var context = new SiteContainer())
            {
                var projectImage = context.FlashContent.Include("Project").First(pi => pi.Id == id);
                var project = projectImage.Project;
                IOHelper.DeleteDirectory("~/Content/FlashContent", projectImage.ImageSource);
                IOHelper.DeleteFile("~/Content/Images", projectImage.ImageSourcePreview);
                context.DeleteObject(projectImage);
                context.SaveChanges();
                return RedirectToAction("Projects", "Home", new { area = "", id = project.Name });
            }
        }