Beispiel #1
0
        public ActionResult Create(BlogEntryModel model, string contentImage, List <string> videoyoutube)
        {
            Business.Services.CustomPrincipal currentUserInfo = (Business.Services.CustomPrincipal)User;
            if (Utils.IsBlogAdmin(currentUserInfo.UserId))
            {
                BlogEntryRepository objblogentry = new BlogEntryRepository(this.SessionCustom);
                ContentManagement   objcontent   = new ContentManagement(this.SessionCustom, HttpContext);

                try
                {
                    model.IContent.Template = "BlogEntry";
                    model.IContent.Widget   = false;
                    model.IContent.Private  = false;
                    model.IContent.Active   = true;
                    model.IContent.Image    = contentImage;

                    objcontent.CollVideos = videoyoutube;
                    this.SessionCustom.Begin();

                    model.IContent.LanguageId = 2;
                    objcontent.ContentInsert(model.IContent, 4);
                    objblogentry.Entity = model.BlogEntry;
                    if (objblogentry.Entity.ContentId != null)
                    {
                        objblogentry.Update();
                        this.InsertAudit("Update", this.Module.Name + " -> " + model.IContent.Name);
                    }
                    else
                    {
                        objblogentry.Entity.ContentId = objcontent.ObjContent.ContentId;
                        objblogentry.Insert();

                        this.InsertAudit("Insert", this.Module.Name + " -> " + model.IContent.Name);
                    }

                    string serverMap = Server.MapPath("~");
                    string origin    = serverMap + @"\resources\temporal\blog\" + contentImage;
                    if (System.IO.File.Exists(origin))
                    {
                        if (!System.IO.Directory.Exists(serverMap + @"\files\" + objblogentry.Entity.ContentId))
                        {
                            System.IO.Directory.CreateDirectory(serverMap + @"\files\" + objblogentry.Entity.ContentId);
                        }

                        System.IO.File.Move(origin, serverMap + @"\files\" + objblogentry.Entity.ContentId + @"\" + contentImage);
                    }

                    this.SessionCustom.Commit();
                    ViewBag.Result = true;
                }
                catch (Exception ex)
                {
                    SessionCustom.RollBack();
                    Utils.InsertLog(
                        this.SessionCustom,
                        "Error" + this.Module.Name,
                        ex.Message + " " + ex.StackTrace);
                    ViewBag.Result = false;
                }

                return(this.View("index", model));
            }

            return(null);
        }
Beispiel #2
0
        public ActionResult Create(BlogEntryModel model, HttpPostedFileBase contentImage, HttpPostedFileBase contentCoverImage, List <string> videoyoutube, string existingTags, string newTags)
        {
            BlogEntryRepository objblogentry = new BlogEntryRepository(this.SessionCustom);
            ContentManagement   objcontent   = new ContentManagement(this.SessionCustom, HttpContext);

            try
            {
                objcontent.ContentImage      = contentImage;
                objcontent.ContentCoverImage = contentCoverImage;
                objcontent.CollVideos        = videoyoutube;
                this.SessionCustom.Begin();

                model.IContent.LanguageId = CurrentLanguage.LanguageId;
                objcontent.ContentInsert(model.IContent, 4);
                objblogentry.Entity = model.BlogEntry;
                objblogentry.Entity.ExistingTags = !string.Empty.Equals(existingTags) ? existingTags : null;
                objblogentry.Entity.NewTags      = !string.Empty.Equals(newTags) ? newTags : null;

                if (objblogentry.Entity.ContentId != null)
                {
                    objblogentry.Update();
                    this.InsertAudit("Update", this.Module.Name + " -> " + model.IContent.Name);
                }
                else
                {
                    if (!string.IsNullOrEmpty(Request.Form["TempFiles"]))
                    {
                        string[] files = Request.Form["TempFiles"].Split(',');

                        if (files.Length > 0)
                        {
                            if (!Directory.Exists(Path.Combine(Server.MapPath("~"), @"Files\" + objcontent.ObjContent.ContentId + @"\")))
                            {
                                Directory.CreateDirectory(Path.Combine(Server.MapPath("~"), @"Files\" + objcontent.ObjContent.ContentId + @"\"));
                            }
                        }

                        foreach (var item in files)
                        {
                            string filep = Path.Combine(Server.MapPath("~"), @"Files\Images\" + Path.GetFileName(item));
                            if (System.IO.File.Exists(filep))
                            {
                                string filedestin = Path.Combine(Server.MapPath("~"), @"Files\Images\" + Path.GetFileName(item));
                                System.IO.File.Move(filep, Path.Combine(Server.MapPath("~"), @"Files\" + objcontent.ObjContent.ContentId + @"\" + Path.GetFileName(item)));
                            }
                        }
                    }

                    objblogentry.Entity.ContentId = objcontent.ObjContent.ContentId;
                    objblogentry.Insert();

                    this.InsertAudit("Insert", this.Module.Name + " -> " + model.IContent.Name);
                }

                this.SessionCustom.Commit();
            }
            catch (Exception ex)
            {
                SessionCustom.RollBack();
                Utils.InsertLog(
                    this.SessionCustom,
                    "Error" + this.Module.Name,
                    ex.Message + " " + ex.StackTrace);
            }

            if (Request.Form["GetOut"] == "0")
            {
                return(this.RedirectToAction("Index", "Content", new { mod = Module.ModulId }));
            }
            else
            {
                return(this.RedirectToAction("Detail", "BlogEntry", new { mod = Module.ModulId, id = objblogentry.Entity.ContentId }));
            }
        }