Пример #1
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);

        }