Ejemplo n.º 1
0
 public IActionResult Create(ContentCreateViewModel model)
 {
     if (ModelState.IsValid)
     {
         string uniqueFileName = null;
         if (model.Image != null)
         {
             string uploadsFolder = Path.Combine(he.WebRootPath, "images");
             uniqueFileName = Guid.NewGuid().ToString() + "_" + model.Image.FileName;
             string filePath = Path.Combine(uploadsFolder, uniqueFileName);
             model.Image.CopyTo(new FileStream(filePath, FileMode.Create));
         }
         Content content = new Content
         {
             Name            = model.Name,
             MetalTitle      = model.MetalTitle,
             Description     = model.Description,
             CategoryId      = model.CategoryId,
             Detail          = model.Detail,
             Warranty        = model.Warranty,
             Image           = uniqueFileName,
             CreatedBy       = CommonConstants.USER_SESSION,
             ModifiedDate    = model.ModifiedDate,
             ModifiedBy      = model.ModifiedBy,
             MetaKeywords    = model.MetaKeywords,
             MetaDescription = model.MetaDescription,
             Status          = model.Status,
             TopHot          = model.TopHot,
         };
         new ContentDao().Create(content);
         return(RedirectToAction("Index"));
     }
     SetViewBag();
     return(View());
 }
Ejemplo n.º 2
0
        public async Task <bool> Inert(ContentCreateViewModel viewModel)
        {
            Content content = mapper.Map <Content>(viewModel);

            repository.Content.Create(content);
            var result = await repository.SaveChanges();

            return(result > 0);
        }
Ejemplo n.º 3
0
        public async Task<IActionResult> Edit(int id, int type)
        {
            var content = await _contentService.FindByIdAsync(id).ConfigureAwait(false);

            var m = new ContentCreateViewModel();
            m.CategoryId = content.CategoryId;
            m.Description = content.Lead;
            m.SeoDescription = content.SeoDescription;
            m.Title = content.Title;
            m.PhotoFileName = content.Pic;
            m.Id = content.Id;
            m.VideoFileName = content.Video;
            m.Priority = content.Priority;

            m.Pic2 = content.Pic2;
            m.Thumbnail2 = content.Thumbnail2;
            m.MediumPic2 = content.MediumPic2;

            m.Pic = content.Pic;
            m.Thumbnail = content.Thumbnail;
            m.MediumPic = content.MediumPic;

            m.Pic3 = content.Pic3;
            m.Thumbnail3 = content.Thumbnail3;
            m.MediumPic3 = content.MediumPic3;

            m.Link = content.Link;
            m.Mp364Bit = content.Mp364;
            m.Mp3128Bit = content.Mp3128;
            m.Mp3320Bit = content.Mp3320;
            m.SvgStr = content.Svg;
            m.HeadLine = content.HeadLine;
            m.SubTitle = content.SubTitle;
            m.SeoTitle = content.SeoTitle;
            m.IsArchive = content.IsArchive;
            m.Tags = content.ContentTags != null
                ? (string.Join(",", content.ContentTags.Select(x => x.Id).ToArray()))
                : "";
            m.ContentTags = content.ContentTags;
            m.ContentFiles = content.ContentFiles;
            m.RegisterDate = content.PublishDateTime.ToShortPersianDateString();
            m.RegisterTime = content.PublishDateTime != null ? content.PublishDateTime.Value.ToString("h:mm:tt") : "";
            m.ContentText = content.ContentText != null
                ? content.ContentText.Replace("../../content/files/editor/", "/content/files/editor/")
                    .Replace("../content/files/editor/", "/content/files/editor/")
                    .Replace("..//content/files/editor/", "/content/files/editor/")
                : "";


            //var cats = _categoryService.FindByIdAsync(content.CategoryId).Result;
            //List<Category> dd=new List<Category>();
            //dd.Add(cats);
            //ViewBag.CategoryId = new SelectList(dd, "Id", "Title", null);
            ViewBag.CategoryName = content.Category.Title;
            return View(viewName: nameof(Edit), model: m);
        }
Ejemplo n.º 4
0
        public ActionResult Create()
        {
            var pages = db.pages.Select(x => new { Text = x.PageName, Value = x.PageId }).ToList();

            pages.Insert(0, null);
            ViewBag.PageId = new SelectList(pages, "Value", "Text");

            var viewModel = new ContentCreateViewModel();

            viewModel.IsPublished = "A";

            return(View(viewModel));
        }
        public async Task <ActionResult> Post([FromBody] ContentCreateViewModel viewModel)
        {
            string msg = string.Empty;

            if (await ContentBLL.Inert(viewModel))
            {
                msg = "新增成功";
            }
            else
            {
                msg = "新增失敗";
            }
            return(Ok(new { ret = msg }));
        }
Ejemplo n.º 6
0
        public ActionResult Create(ContentCreateViewModel viewModel)
        {
            var pages = db.pages.Select(x => new { Text = x.PageName, Value = x.PageId }).ToList();

            pages.Insert(0, null);
            ViewBag.PageId = new SelectList(pages, "Value", "Text", viewModel.PageId);

            if (ModelState.IsValid)
            {
                var contentExists = db.contents.Where(x => x.Title == viewModel.Title.Trim() && x.PageId == viewModel.PageId);
                if (contentExists.Count() > 0)
                {
                    ModelState.AddModelError("", "Content already exists.");
                }
                else
                {
                    var page       = db.pages.Find(viewModel.PageId);
                    var titleUrl   = viewModel.Title.Trim().ToLower().Replace(' ', '-');
                    var contentUrl = page.PageUrl + "/" + titleUrl;

                    // Upload Image //
                    var imageUri = !String.IsNullOrEmpty(viewModel.ImageUrl) ?
                                   new ImageUploader().AzureBlobUpload(viewModel.ImageUrl.Replace("data:image/png;base64,", ""), titleUrl + ".png") : null;

                    var model = new content();
                    model.PageId      = viewModel.PageId;
                    model.Title       = viewModel.Title.Trim();
                    model.ContentUrl  = contentUrl;
                    model.Subtitle    = viewModel.Subtitle;
                    model.ImageUrl    = imageUri;
                    model.Content1    = viewModel.Content;
                    model.IsPublished = viewModel.IsPublished == "A";
                    model.CreatedBy   = User.Identity.Name;
                    model.CreatedDate = DateTime.Now;

                    db.contents.Add(model);
                    db.SaveChanges();

                    return(RedirectToAction("index"));
                }
            }

            return(View(viewModel));
        }
Ejemplo n.º 7
0
        public IActionResult Edit(long id)
        {
            var dao     = new ContentDao();
            var content = dao.GetByID(id);

            SetViewBag(content.CategoryId);
            ContentCreateViewModel result = new ContentCreateViewModel
            {
                Name            = content.Name,
                MetalTitle      = content.MetalTitle,
                Description     = content.Description,
                CategoryId      = content.CategoryId,
                Detail          = content.Detail,
                Warranty        = content.Warranty,
                ModifiedDate    = content.ModifiedDate,
                ModifiedBy      = content.ModifiedBy,
                MetaKeywords    = content.MetaKeywords,
                MetaDescription = content.MetaDescription,
                Status          = content.Status,
                TopHot          = content.TopHot,
            };

            return(View(result));
        }
Ejemplo n.º 8
0
        public async Task<IActionResult> Edit(ContentCreateViewModel model, int id)
        {
            try
            {

                if (!ModelState.IsValid)
                {
                    ViewBag.CurrentDate = DateTime.Now.ToShortPersianDateString();

                    var cats = _categoryService.GetIndentedCategory(model.TypeId);


                    int? selected = null;
                    selected = model.CategoryId;

                    ViewBag.CategoryId = new SelectList(cats, "Id", "Title", selected);
                    return View(model);
                }






                var content = await _contentService.FindByIdAsync(id).ConfigureAwait(false);
                content.Lead = model.Description;
                content.CategoryId = (int)model.CategoryId;
                content.Title = model.Title.Trim();
                content.Thumbnail = model.Thumbnail;
                content.MediumPic = model.MediumPic;
                content.Pic = model.Pic;
                content.Priority = model.Priority;
                content.Link = model.Link;
                content.HeadLine = model.HeadLine;
                content.SeoTitle = model.SeoTitle;
                content.Video = model.VideoFileName;
                content.SeoDescription = model.SeoDescription;
                content.Pdf = model.PdfFileName;
                // content.ContentFiles = model.ContentFiles;

                content.SubTitle = model.SubTitle;
                content.ContentText = model.ContentText != null
                    ? model.ContentText
                        .Replace("../../content/files/editor/", "/content/files/editor/")
                        .Replace("../content/files/editor/", "/content/files/editor/")
                        .Replace("..//content/files/editor/", "/content/files/editor/")
                    : "";

                if (model.RegisterTime.ToLower().Contains("pm"))
                {
                    var m = model.RegisterTime.Split(":");
                    model.RegisterTime = (Convert.ToInt32(m[0]) == 12 ? 0 : Convert.ToInt32(m[0])) + 12 + ":" +
                                         m[1].ToLower().Replace("pm", "").Trim();

                }

                content.PublishDateTime =
                    (model.RegisterDate + " , " + model.RegisterTime.ToLower().Replace("am", "").Trim())
                    .ToGregorianDateTime();
                if (model.Tags != null)
                {
                    var tags = model.Tags.Split(",");
                    List<ContentTag> c = new List<ContentTag>();
                    foreach (var t in tags)
                    {
                        c.Add(new ContentTag
                        {
                            TagId = Convert.ToInt32(t),
                        });

                    }

                    content.ContentTags.Clear();
                    content.ContentTags = c;
                }
                else
                {
                    content.ContentTags.Clear();
                }



                if (model.Svg != null)

                    using (var reader = new StreamReader(model.Svg.OpenReadStream()))
                    {
                        content.Svg = reader.ReadToEnd().Replace("\n", " ").Replace("\r", " ").Replace("\t", " ")
                            .Replace(
                                "<!-- Generator: Adobe Illustrator 16.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->",
                                "");
                    }


                else

                    content.Svg = model.SvgStr;


                _contentService.UpdateContent(content, model.Photo, model.Photo2, model.Photo3, model.Files,
                    model.Video, model.Pdf, model.Mp364, model.Mp3128, model.Mp3320);

                return RedirectToAction(nameof(Index), new { type = content.TypeId });
            }
            catch (Exception e)
            {
                return View();
            }
        }
Ejemplo n.º 9
0
        public ActionResult Create(ContentCreateViewModel model)
        {

            if (ModelState.IsValid)
            {
                var result = string.Empty;

                if (model.Svg != null)
                {
                    using (var reader = new StreamReader(model.Svg.OpenReadStream()))
                    {
                        result = reader.ReadToEnd().Replace("\n", " ").Replace("\r", " ").Replace("\t", " ")
                            .Replace(
                                "<!-- Generator: Adobe Illustrator 16.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->",
                                "");
                    }
                }

                var user = new Content
                {
                    Title = model.Title.Trim(),
                    Lead = model.Description,
                    Priority = model.Priority,
                    //CategoryId = (int)model.CategoryId,
                    TypeId = model.TypeId,
                    Svg = result,
                    Link = model.Link,
                    IsArchive = model.IsArchive,
                    HeadLine = model.HeadLine,
                    SubTitle = model.SubTitle,
                    SeoDescription = model.SeoDescription,
                    SeoTitle = model.SeoTitle,
                    ContentText = model.ContentText != null
                        ? model.ContentText.Replace("../../content/files/editor/", "/content/files/editor/")
                            .Replace("../content/files/editor/", "/content/files/editor/")
                        : ""
                };


                if (model.RegisterTime.ToLower().Contains("pm"))
                {
                    var m = model.RegisterTime.Split(":");
                    model.RegisterTime = (Convert.ToInt32(m[0]) == 12 ? 0 : Convert.ToInt32(m[0])) + 12 + ":" +
                                         m[1].ToLower().Replace("pm", "").Trim();
                }

                user.PublishDateTime =
                    (model.RegisterDate + " , " + model.RegisterTime.ToLower().Replace("am", "").Trim())
                    .ToGregorianDateTime();

                if (model.Tags != null)
                {
                    var tags = model.Tags.Split(",");
                    List<ContentTag> c = new List<ContentTag>();
                    foreach (var t in tags)
                    {
                        c.Add(new ContentTag
                        {
                            TagId = Convert.ToInt32(t),
                        });
                    }

                    user.ContentTags = c;
                }

                _contentService.AddNewContent(user, model.Photo, model.Photo2, model.Photo3, model.Files, model.Video,
                    model.Pdf, model.Mp364, model.Mp3128, model.Mp3320);

                _uow.SaveChanges();

                return RedirectToAction(nameof(Index), new { type = user.TypeId, categoryid = user.CategoryId });

            }

            ViewBag.CurrentDate = DateTime.Now.ToShortPersianDateString();

            var cats = _categoryService.GetIndentedCategory(model.TypeId);


            //int? selected = null;
            //selected = model.CategoryId;

            //ViewBag.CategoryId = new SelectList(cats, "Id", "Title", selected);
            return View(model);

        }