コード例 #1
0
        public async Task <IActionResult> AddEdit(HomeSlide homeSlide)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var _homeSlide = _mapper.Map <HomeSlide>(homeSlide);
                    var dbSlide    = await _homeSlideService.GetAsync(x => x.Id == homeSlide.Id, new string[] { });

                    if (dbSlide?.Data != null)
                    {
                        _homeSlide.CreateDate = dbSlide.Data.CreateDate;
                        _homeSlide.SlidePath  = dbSlide.Data.SlidePath;
                    }
                    else
                    {
                        _homeSlide.CreateDate = DateTime.Now;
                    }

                    if (Request.Form.Files.Count > 0)
                    {
                        _homeSlide.SlidePath = SaveFile(_hostingEnvironment.ContentRootPath, "homeSlider");
                    }

                    if (homeSlide.Id == 0)
                    {
                        homeSlide.UserId = CurrentUser.UserId;
                    }
                    var result = _homeSlide.Id == 0
                        ? await _homeSlideService.CreateAsync(homeSlide)
                        : await _homeSlideService.EditAsync(homeSlide);

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

            return(Json(Result.Create(false, 500)));
        }
コード例 #2
0
        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)));
        }
コード例 #3
0
ファイル: HomeController.cs プロジェクト: ali8465/Mobicom
        public async Task <IActionResult> SystemSetting(SystemSetting model)
        {
            var result = await _systemSettingService.EditAsync(model);

            return(Json(result));
        }