예제 #1
0
        public ActionResult Create(ListViewModel model, HttpPostedFileBase FileUp)
        {
            var guid = Guid.NewGuid().ToString();

            var items = new ItemList()
            {
                MagazineId = model.MagazineId,
                Name       = model.Name,
                ItemListId = model.ItemListId,
                Content    = model.Content,
                IsDeleted  = model.IsDeleted
            };

            if (FileUp.ContentLength > 0)
            {
                string ext = System.IO.Path.GetExtension(FileUp.FileName);
                if (ext == ".pdf")
                {
                    string Filename = guid + ext;

                    var originalDirectory =
                        new DirectoryInfo(string.Format(Server.MapPath("~/Content/Pdf/")));

                    string pathString = System.IO.Path.Combine(originalDirectory.ToString(), "");

                    bool isExists = System.IO.Directory.Exists(pathString);

                    if (!isExists)
                    {
                        System.IO.Directory.CreateDirectory(pathString);
                    }

                    var path = string.Format("{0}\\{1}", pathString, Filename);

                    FileUp.SaveAs(path);

                    items.Content = "http://TheContent.mx/Content/pdf/" + Filename;
                }
                else
                {
                    SetMessage("Solo puedes subir archivos Pdf.", BootstrapAlertTypes.Danger);
                    return(View(model));
                }
            }

            try
            {
                var list = ListService.CreateListOfItems(items);

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View(model));
            }
        }