public ActionResult EditPost(Guid id, IList <GalleryImage> images, Guid?links, AreaKind farea, IList <Tag> tags)
        {
            CaseStudy caseStudy;

            if (Guid.Empty.Equals(id))
            {
                caseStudy = new CaseStudy();
            }
            else
            {
                caseStudy             = DbSession.Get <CaseStudy>(id);
                caseStudy.Image       = null;
                caseStudy.SharedLinks = null;
            }
            if (TryUpdateModel(caseStudy))
            {
                caseStudy.Tags.Clear();
                if (tags != null)
                {
                    foreach (var dtoTag in tags)
                    {
                        caseStudy.Tags.Add(DbSession.Get <Tag>(dtoTag.ID));
                    }
                }
                caseStudy.Area = DbSession.Get <Area>(farea);
                if (images != null)
                {
                    ImagesController.SaveImages(images, DbSession);
                    caseStudy.Image = images.FirstOrDefault(img => !img.ShouldDelete);
                }
                if (links.HasValue)
                {
                    caseStudy.SharedLinks = DbSession.Get <CmsBlock>(links.Value);
                }

                DbSession.SaveOrUpdate(caseStudy);
                DbSession.Flush();
                return(RedirectToAction("Edit", new { id = caseStudy.ID }));
            }

            ViewBag.Areas     = DbSession.GetAll <Area>(true);
            ViewBag.CmsBlocks = DbSession.GetAll <CmsBlock>(true);
            return(View(caseStudy));
        }
예제 #2
0
        public ActionResult EditPost(Guid id, IList <GalleryImage> images, Guid?links, AreaKind farea)
        {
            Article article;

            if (Guid.Empty.Equals(id))
            {
                article = new Article();
            }
            else
            {
                article             = DbSession.Get <Article>(id);
                article.Image       = null;
                article.SharedLinks = null;
            }
            if (TryUpdateModel(article))
            {
                var dtos = article.Tags.ToList();
                article.Tags.Clear();
                foreach (var dtoTag in dtos)
                {
                    article.Tags.Add(DbSession.Get <Tag>(dtoTag.ID));
                }
                article.Area = DbSession.Get <Area>(farea);
                if (images != null)
                {
                    ImagesController.SaveImages(images, DbSession);
                    article.Image = images.FirstOrDefault(img => !img.ShouldDelete);
                }
                if (links.HasValue)
                {
                    article.SharedLinks = DbSession.Get <CmsBlock>(links.Value);
                }

                DbSession.SaveOrUpdate(article);
                DbSession.Flush();
                return(RedirectToAction("Edit", new { id = article.ID }));
            }

            ViewBag.Areas     = DbSession.GetAll <Area>(true);
            ViewBag.CmsBlocks = DbSession.GetAll <CmsBlock>(true);
            return(View(article));
        }
예제 #3
0
        public ActionResult EditPost(Guid id, AreaKind farea, IList <GalleryImage> images)
        {
            CustomerReview page;

            if (Guid.Empty.Equals(id))
            {
                page = new CustomerReview();
            }
            else
            {
                page       = DbSession.Get <CustomerReview>(id);
                page.Image = null;
                page.Tags.Clear();
            }
            if (TryUpdateModel(page))
            {
                var dtos = page.Tags.ToList();
                page.Tags.Clear();
                foreach (var dtoTag in dtos)
                {
                    page.Tags.Add(DbSession.Get <Tag>(dtoTag.ID));
                }
                page.Area = DbSession.Get <Area>(farea);
                if (images != null)
                {
                    ImagesController.SaveImages(images, DbSession);
                    page.Image = images.FirstOrDefault(img => !img.ShouldDelete);
                }
                DbSession.SaveOrUpdate(page);
                DbSession.Flush();
                return(RedirectToAction("Edit", new { id = page.ID }));
            }

            ViewBag.Areas = DbSession.GetAll <Area>(true);
            return(View(page));
        }
        public ActionResult EditPost(AreaKind id, Guid?flinks, Guid?footer, IList <GalleryImage> flargeImages, IList <GalleryImage> fsmallImages, HttpPostedFileBase qa1, HttpPostedFileBase qa2, HttpPostedFileBase qa3, HttpPostedFileBase qa4)
        {
            Area area;

            if (id == AreaKind.New)
            {
                area = new Area();
            }
            else
            {
                area       = DbSession.Get <Area>(id);
                area.Links = null;
                area.ArticleTags.Clear();
                area.CaseStudyTags.Clear();
                area.PhotoTags.Clear();
            }
            var oldqa1 = area.QuoteAttachment1;
            var oldqa2 = area.QuoteAttachment2;
            var oldqa3 = area.QuoteAttachment3;
            var oldqa4 = area.QuoteAttachment4;

            if (TryUpdateModel(area))
            {
                using (var trans = DbSession.BeginTransaction()) {
                    try {
                        var tagDtos = area.ArticleTags.ToList();
                        area.ArticleTags.Clear();
                        foreach (var dtoTag in tagDtos)
                        {
                            area.ArticleTags.Add(DbSession.Get <Tag>(dtoTag.ID));
                        }

                        tagDtos = area.DownloadTags.ToList();
                        area.DownloadTags.Clear();
                        foreach (var dtoTag in tagDtos)
                        {
                            area.DownloadTags.Add(DbSession.Get <Tag>(dtoTag.ID));
                        }

                        tagDtos = area.CaseStudyTags.ToList();
                        area.CaseStudyTags.Clear();
                        foreach (var dtoTag in tagDtos)
                        {
                            area.CaseStudyTags.Add(DbSession.Get <Tag>(dtoTag.ID));
                        }

                        tagDtos = area.PhotoTags.ToList();
                        area.PhotoTags.Clear();
                        foreach (var dtoTag in tagDtos)
                        {
                            area.PhotoTags.Add(DbSession.Get <Tag>(dtoTag.ID));
                        }

                        tagDtos = area.CustomerReviewTags.ToList();
                        area.CustomerReviewTags.Clear();
                        foreach (var dtoTag in tagDtos)
                        {
                            area.CustomerReviewTags.Add(DbSession.Get <Tag>(dtoTag.ID));
                        }

                        if (qa1 != null)
                        {
                            var name = Path.GetFileNameWithoutExtension(qa1.FileName).Trim().Replace(" ", "-");
                            var ext  = Path.GetExtension(qa1.FileName).ToLower();
                            var path = "/content/uploads/" + Guid.NewGuid() + "/";
                            var dir  = Server.MapPath(path);
                            if (!Directory.Exists(dir))
                            {
                                Directory.CreateDirectory(dir);
                            }
                            var url = path + name + ext;
                            qa1.SaveAs(Server.MapPath(url));
                            area.QuoteAttachment1 = url;
                        }
                        if (qa2 != null)
                        {
                            var name = Path.GetFileNameWithoutExtension(qa2.FileName).Trim().Replace(" ", "-");
                            var ext  = Path.GetExtension(qa2.FileName).ToLower();
                            var path = "/content/uploads/" + Guid.NewGuid() + "/";
                            var dir  = Server.MapPath(path);
                            if (!Directory.Exists(dir))
                            {
                                Directory.CreateDirectory(dir);
                            }
                            var url = path + name + ext;
                            qa2.SaveAs(Server.MapPath(url));
                            area.QuoteAttachment2 = url;
                        }
                        if (qa3 != null)
                        {
                            var name = Path.GetFileNameWithoutExtension(qa3.FileName).Trim().Replace(" ", "-");
                            var ext  = Path.GetExtension(qa3.FileName).ToLower();
                            var path = "/content/uploads/" + Guid.NewGuid() + "/";
                            var dir  = Server.MapPath(path);
                            if (!Directory.Exists(dir))
                            {
                                Directory.CreateDirectory(dir);
                            }
                            var url = path + name + ext;
                            qa3.SaveAs(Server.MapPath(url));
                            area.QuoteAttachment3 = url;
                        }
                        if (qa4 != null)
                        {
                            var name = Path.GetFileNameWithoutExtension(qa4.FileName).Trim().Replace(" ", "-");
                            var ext  = Path.GetExtension(qa4.FileName).ToLower();
                            var path = "/content/uploads/" + Guid.NewGuid() + "/";
                            var dir  = Server.MapPath(path);
                            if (!Directory.Exists(dir))
                            {
                                Directory.CreateDirectory(dir);
                            }
                            var url = path + name + ext;
                            qa4.SaveAs(Server.MapPath(url));
                            area.QuoteAttachment4 = url;
                        }

                        //large images
                        if (flargeImages != null)
                        {
                            foreach (var img in flargeImages)
                            {
                                if (img.ShouldDelete && area.LargeImages.Contains(img))
                                {
                                    area.LargeImages.Remove(img);
                                }
                                if (!img.ShouldDelete && !area.LargeImages.Contains(img))
                                {
                                    area.LargeImages.Add(img);
                                }
                            }
                            ImagesController.SaveImages(flargeImages, DbSession);
                        }


                        //small images
                        if (fsmallImages != null)
                        {
                            foreach (var img in fsmallImages)
                            {
                                if (img.ShouldDelete && area.SmallImages.Contains(img))
                                {
                                    area.SmallImages.Remove(img);
                                }
                                if (!img.ShouldDelete && !area.SmallImages.Contains(img))
                                {
                                    area.SmallImages.Add(img);
                                }
                            }
                            ImagesController.SaveImages(fsmallImages, DbSession);
                        }

                        //links
                        if (flinks.HasValue)
                        {
                            area.Links = DbSession.Get <CmsBlock>(flinks.Value);
                        }

                        area.FooterLinksID = footer;

                        DbSession.SaveOrUpdate(area);
                        DbSession.Flush();
                        trans.Commit();

                        //try to delete deleted files
                        if (!String.IsNullOrEmpty(oldqa1) && String.IsNullOrEmpty(area.QuoteAttachment1))
                        {
                            try {
                                System.IO.File.Delete(Server.MapPath(oldqa1));
                            } catch { }
                        }
                        if (!String.IsNullOrEmpty(oldqa2) && String.IsNullOrEmpty(area.QuoteAttachment2))
                        {
                            try {
                                System.IO.File.Delete(Server.MapPath(oldqa2));
                            } catch { }
                        }
                        if (!String.IsNullOrEmpty(oldqa3) && String.IsNullOrEmpty(area.QuoteAttachment3))
                        {
                            try {
                                System.IO.File.Delete(Server.MapPath(oldqa3));
                            } catch { }
                        }
                        if (!String.IsNullOrEmpty(oldqa4) && String.IsNullOrEmpty(area.QuoteAttachment4))
                        {
                            try {
                                System.IO.File.Delete(Server.MapPath(oldqa4));
                            } catch { }
                        }
                    } catch {
                        trans.Rollback();
                        throw;
                    }
                }
                return(RedirectToAction("Edit", new { id = area.ID }));
            }

            ViewBag.CmsBlocks = DbSession.GetAll <CmsBlock>(true);
            return(View(area));
        }