Ejemplo n.º 1
0
        public async Task <IActionResult> Create(CMSViewModels item, IFormFile FileUploadId)
        {
            var content = "";

            if (item.HtmlType == 1)
            {
                content = item.ContentId;
            }
            else
            if (item.HtmlType == 2)
            {
                content = item.TextAreaId;
            }
            else

            if (item.HtmlType == 3)
            {
                content = item.HtmlEditorId;
            }
            else
            {
                if (item.FileUploadId != null)
                {
                    var filename = item.FileUploadId.FileName;
                    var path     = Path.Combine(_hostingEnvironment.WebRootPath + "\\siteimages", filename);
                    var relpath  = "/siteimages/" + filename;

                    content = relpath;
                    using (var stream = new FileStream(path, FileMode.Create))
                    {
                        await item.FileUploadId.CopyToAsync(stream);
                    }
                }
            }
            ViewBag.MenuItems = new SelectList(new MenuItemManager().GetAll(), "ItemId", "Name");
            ViewBag.HtmlTypes = new SelectList(new HtmlTypesManager().GetAll(), "Id", "Name");
            item.Content      = content;

            if (ModelState.IsValid)
            {
                if (item.Id > 0)
                {
                    if (string.IsNullOrWhiteSpace(item.Content))
                    {
                        var oldItem = new CMSManager().GetById(item.Id);
                        item.Content = oldItem.Content;
                    }
                    new CMSManager().Update(new CMSViewModels().Transform(item));
                }
                else
                {
                    new CMSManager().Create(new CMSViewModels().Transform(item));
                }

                return(RedirectToAction("Index"));
            }
            return(View(item));
        }
Ejemplo n.º 2
0
        public IActionResult Create(int id)

        {
            ViewBag.MenuItems = new SelectList(new MenuItemManager().GetAll(), "ItemId", "Name");
            ViewBag.HtmlTypes = new SelectList(new HtmlTypesManager().GetAll(), "Id", "Name");

            var viewModel = new CMSViewModels();

            if (id > 0)
            {
                viewModel = (CMSViewModels)(new CMSManager().GetById(id));
            }

            return(View(viewModel));
        }