Example #1
0
        public async Task <IActionResult> AddEdit(Category category)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var _category = _mapper.Map <Category>(category);
                    if (Request.Form.Files.Count != 0 && Request.Form.Files["image"] != null && Request.Form.Files["image"].Length != 0)
                    {
                        category.SlidePath = SaveFile(_hostingEnvironment.ContentRootPath, "pageHeader");
                    }
                    if (Request.Form.Files.Count != 0 && Request.Form.Files["mobile-image"] != null && Request.Form.Files["mobile-image"].Length != 0)
                    {
                        category.MobileSlidePath = SaveFile(_hostingEnvironment.ContentRootPath, "pageHeader");
                    }
                    category.SeoFriendlyUrl = SeoFriendlyUrlHelper.GetFriendlyTitle(string.IsNullOrEmpty(category.SeoFriendlyUrl)
                        ? category.Title
                        : category.SeoFriendlyUrl);
                    var result = _category.Id == 0
                        ? await _categoryService.CreateAsync(category)
                        : await _categoryService.EditAsync(category);

                    return(Json(result));
                }
            }
            catch (Exception ex)
            {
                //ToDo log
            }

            return(Json(Result.Create(false, 500)));
        }
        public async Task <IActionResult> AddEdit(News news)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var _news  = _mapper.Map <News>(news);
                    var dbNews = await _newsService.GetAsync(x => x.Id == news.Id, new string[] { });

                    news.SeoFriendlyUrl = SeoFriendlyUrlHelper.GetFriendlyTitle(string.IsNullOrEmpty(news.SeoFriendlyUrl)
                        ? news.Title
                        : news.SeoFriendlyUrl);
                    if (news.Id == 0)
                    {
                        news.CreateDate = DateTime.Now;
                        news.UserId     = CurrentUser.UserId;
                    }
                    else
                    {
                        news.CreateDate = dbNews.Data.CreateDate;
                    }

                    if (Request.Form.Files.Count > 0)
                    {
                        news.Image = SaveFile(_hostingEnvironment.ContentRootPath, "images/news", true);
                    }
                    news.Body = string.IsNullOrEmpty(news.Body) ? "<p></p>" : news.Body;
                    var result = _news.Id == 0
                        ? await _newsService.CreateAsync(news)
                        : await _newsService.EditAsync(news);

                    return(Json(result));
                }
            }
            catch (Exception ex)
            {
                return(Json(Result.Create(false, ex.Message, 500))); //ToDo log
            }

            return(Json(Result.Create(false, 500)));
        }
Example #3
0
        public async Task <IActionResult> AddEdit(Content content)
        {
            var categoryList = await _categoryService.GetListAllAsync("Sort", true, new string[] { });

            ViewBag.CategoryList = new SelectList(categoryList.Data, "Id", "Title");
            try
            {
                if (ModelState.IsValid)
                {
                    var _content  = _mapper.Map <Content>(content);
                    var dbContent = await _contentService.GetAsync(x => x.Id == content.Id, new string[] { });

                    _content.CreateDate = _content.Id == 0 ? DateTime.Now : dbContent.Data.CreateDate;
                    _content.UserId     = CurrentUser.UserId;
                    _content.IsMenu     = true;
                    _content.Icon       = string.IsNullOrEmpty(_content.Icon) ? dbContent.Data?.Icon : _content.Icon;
                    if (Request.Form.Files.Count != 0)
                    {
                        _content.Icon = SaveFile(_hostingEnvironment.ContentRootPath);
                    }
                    _content.SeoFriendlyUrl = SeoFriendlyUrlHelper.GetFriendlyTitle(string.IsNullOrEmpty(content.SeoFriendlyUrl)
                        ? content.Title
                        : content.SeoFriendlyUrl);
                    var result = _content.Id == 0
                        ? await _contentService.CreateAsync(content)
                        : await _contentService.EditAsync(content);

                    return(Json(result));
                }
            }
            catch (Exception ex)
            {
                //ToDo log
            }

            return(Json(Result.Create(false, 500)));
        }