Esempio n. 1
0
        public async Task <ActionResult> SetRoleMenus(int id, int[] menuId)
        {
            if (id > 0)
            {
                //_roleServices.SetRoleMenus(id, menuId);

                var rolemenus = _context.RoleMenus.Where(d => d.RoleId == id).ToList();
                _context.RemoveRange(rolemenus);

                if (menuId != null)
                {
                    foreach (var mid in menuId)
                    {
                        _context.RoleMenus.Add(new RoleMenu {
                            RoleId = id, MenuId = mid
                        });
                    }
                }
                await _context.SaveChangesAsync();


                //var cacheKey = "MENU";
                //_cache.Invalidate(cacheKey);

                return(Json(AR));
            }
            AR.Setfailure("编辑角色权限失败");
            return(Json(AR));
        }
Esempio n. 2
0
        public async Task <JsonResult> SetPassword(SetPasswordIM model)
        {
            if (!ModelState.IsValid)
            {
                var errorMes = GetModelErrorMessage();
                AR.Setfailure(errorMes);
                return(Json(AR));
            }

            var user = await _context.Users.FindAsync(model.UserId);

            //try
            //{

            var securityStamp = Hash.GenerateSalt();
            var pwdHash       = Hash.HashPasswordWithSalt(model.NewPassword, securityStamp);

            user.SecurityStamp = Convert.ToBase64String(securityStamp);
            user.PasswordHash  = pwdHash;
            _context.Update(user);
            var result = await _context.SaveChangesAsync();



            //var result = _userServices.SetPassword(model.UserId, model.NewPassword);
            if (result > 0)
            {
                AR.Id = model.UserId;
                AR.SetSuccess(Messages.AlertActionSuccess);
                return(Json(AR));
            }
            AR.Setfailure(Messages.AlertActionFailure);
            return(Json(AR));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,Title,Sketch,Importance,Active,Code")] AdvertisingSpaceIM advertisingSpace)
        {
            if (!ModelState.IsValid)
            {
                AR.Setfailure(GetModelErrorMessage());
                return(Json(AR));
            }


            try
            {
                if (advertisingSpace.Id > 0)
                {
                    var model = await _context.AdvertisingSpaces.FindAsync(advertisingSpace.Id);

                    model = _mapper.Map(advertisingSpace, model);


                    model.UpdatedDate = DateTime.Now;
                    model.UpdatedBy   = User.Identity.Name;

                    _context.Update(model);
                    await _context.SaveChangesAsync();

                    AR.SetSuccess(string.Format(Messages.AlertUpdateSuccess, EntityNames.Position));
                }
                else
                {
                    var model = _mapper.Map <AdvertisingSpace>(advertisingSpace);

                    model.CreatedDate = DateTime.Now;
                    model.CreatedBy   = User.Identity.Name;

                    _context.Add(model);
                    await _context.SaveChangesAsync();

                    AR.SetSuccess(string.Format(Messages.AlertCreateSuccess, EntityNames.Page));
                }

                return(Json(AR));
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AdvertisingSpaceExists(advertisingSpace.Id))
                {
                    AR.Setfailure(Messages.HttpNotFound);
                    return(Json(AR));
                }
                else
                {
                    throw;
                }
            }
        }
Esempio n. 4
0
        public async Task <IActionResult> Create([Bind("Id,Title,Summary,Body,Author,Description,Keywords,Thumbnail,Pubdate,ViewCount,Active,CategoryId,CreatedBy,CreatedDate,UpdatedBy,UpdatedDate")] Article article)
        {
            if (ModelState.IsValid)
            {
                _context.Add(article);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoryId"] = new SelectList(_context.ArticleCategories, "Id", "Alias", article.CategoryId);
            return(View(article));
        }
Esempio n. 5
0
        public async Task <IActionResult> DownloadAsync(int id)
        {
            var file = await _context.Documents.FindAsync(id);

            if (file == null)
            {
                return(NotFound());
            }

            var path = _hostingEnvironment.WebRootPath + file.FileUrl;

            if (!System.IO.File.Exists(path))
            {
                return(NotFound());
            }

            file.DownloadCount++;

            _context.Update(file);
            await _context.SaveChangesAsync();

            var fs = new FileStream(path, FileMode.Open);

            return(File(fs, "application/octet-stream", Path.GetFileName(path)));
        }
Esempio n. 6
0
        public async Task <IActionResult> Detail(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var article = await _context.Branches
                          .FindAsync(id);

            if (article == null)
            {
                return(NotFound());
            }

            article.ViewCount++;
            _context.Update(article);
            await _context.SaveChangesAsync();


            var objectId = id.ToString();

            ViewData["PageMeta"] = await _context.PageMetas.FirstOrDefaultAsync(d => d.ObjectId == objectId && d.ModuleType == (short)ModuleType.BRANCH);

            return(View(article));
        }
Esempio n. 7
0
        protected async Task CreatedUpdatedPageMetaAsync(QNZContext db, PageMeta pm)
        {
            var origin = await db.PageMetas.FirstOrDefaultAsync(d => d.ModuleType == pm.ModuleType && d.ObjectId == pm.ObjectId);

            if (origin != null)
            {
                if (string.IsNullOrEmpty(pm.Title) && string.IsNullOrEmpty(pm.Keywords) && string.IsNullOrEmpty(pm.Description))
                {
                    db.Remove(origin);
                }
                else
                {
                    origin.Title       = pm.Title;
                    origin.Keywords    = pm.Keywords;
                    origin.Description = pm.Description;

                    db.Entry(origin).State = EntityState.Modified;
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(pm.Title) || !string.IsNullOrEmpty(pm.Keywords) || !string.IsNullOrEmpty(pm.Description))
                {
                    db.Add(pm);
                }
            }

            await db.SaveChangesAsync();
        }
Esempio n. 8
0
        public async Task <IActionResult> DeleteMulti(int[] ids)
        {
            var c = await _context.Logs.Where(d => ids.Contains(d.Id)).ToListAsync();

            if (c == null)
            {
                AR.Setfailure(Messages.HttpNotFound);
                return(Json(AR));
            }

            _context.Logs.RemoveRange(c);
            await _context.SaveChangesAsync();

            using (LogContext.PushProperty("LogEvent", Buttons.Delete))
            {
                Serilog.Log.Information("删除日志:ID[{logIds}]", string.Join(",", ids));
            }

            return(Json(AR));
        }
Esempio n. 9
0
        public async Task <IActionResult> Edit([Bind("Id,Title,Description,WebLink,ImageUrl,ImageUrlMobile,Importance,Active,SpaceId")] AdvertisementIM advertisement)
        {
            if (!ModelState.IsValid)
            {
                AR.Setfailure(GetModelErrorMessage());
                return(Json(AR));
            }


            try
            {
                if (advertisement.Id > 0)
                {
                    var model = await _context.Advertisements.FirstOrDefaultAsync(d => d.Id == advertisement.Id);

                    if (model == null)
                    {
                        AR.Setfailure(Messages.HttpNotFound);
                        return(Json(AR));
                    }
                    model = _mapper.Map(advertisement, model);

                    model.UpdatedBy   = User.Identity.Name;
                    model.UpdatedDate = DateTime.Now;


                    _context.Update(model);
                    await _context.SaveChangesAsync();

                    AR.SetSuccess(string.Format(Messages.AlertUpdateSuccess, EntityNames.Carousel));
                }
                else
                {
                    var model = _mapper.Map <Advertisement>(advertisement);

                    model.CreatedBy   = User.Identity.Name;
                    model.CreatedDate = DateTime.Now;

                    _context.Add(model);
                    await _context.SaveChangesAsync();


                    AR.SetSuccess(string.Format(Messages.AlertCreateSuccess, EntityNames.Carousel));
                }
                _cacheService.Invalidate("ADVERTISEMENT");
                return(Json(AR));
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AdvertisementExists(advertisement.Id))
                {
                    AR.Setfailure(Messages.HttpNotFound);
                    return(Json(AR));
                }
                else
                {
                    throw;
                }
            }
        }
Esempio n. 10
0
        public async Task <ActionResult <Work> > GetWork(int id)
        {
            var work = await _context.Works.FindAsync(id);

            if (work == null)
            {
                return(NotFound());
            }
            work.ViewCount++;
            _context.Update(work);
            await _context.SaveChangesAsync();

            return(work);
        }
Esempio n. 11
0
        public async Task <IActionResult> InternalServerError(int code)
        {
            var vm = new ErrorVM
            {
                StatusCode = code
            };

            if (code == 404)
            {
                var page = await _context.Pages.FirstOrDefaultAsync(d => d.SeoName == "404");

                if (page != null)
                {
                    page.ViewCount++;
                    _context.Update(page);
                    await _context.SaveChangesAsync();

                    vm.PageDetail = _mapper.Map <PageDetailVM>(page);
                }
            }
            else
            {
                var page = await _context.Pages.FirstOrDefaultAsync(d => d.SeoName == "server_error");

                if (page != null)
                {
                    page.ViewCount++;
                    _context.Update(page);
                    await _context.SaveChangesAsync();

                    vm.PageDetail = _mapper.Map <PageDetailVM>(page);
                }
            }

            return(View(vm));
        }
Esempio n. 12
0
        public async Task <IActionResult> Edit([Bind("Id,Year,Month,Date,Description,Active")] MemorabiliaIM page)
        {
            if (!ModelState.IsValid)
            {
                AR.Setfailure(GetModelErrorMessage());
                return(Json(AR));
            }


            try
            {
                if (page.Id > 0)
                {
                    var model = await _context.Memorabilia.SingleOrDefaultAsync(d => d.Id == page.Id);

                    model             = _mapper.Map(page, model);
                    model.UpdatedDate = DateTime.Now;
                    model.UpdatedBy   = User.Identity.Name;

                    _context.Update(model);
                    await _context.SaveChangesAsync();

                    AR.SetSuccess(string.Format(Messages.AlertUpdateSuccess, EntityNames.Memorabilia));
                }
                else
                {
                    var model = _mapper.Map <Memorabilium>(page);

                    model.CreatedDate = DateTime.Now;
                    model.CreatedBy   = User.Identity.Name;

                    _context.Add(model);
                    await _context.SaveChangesAsync();

                    AR.SetSuccess(string.Format(Messages.AlertCreateSuccess, EntityNames.Memorabilia));
                }



                return(Json(AR));
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PageExists(page.Id))
                {
                    AR.Setfailure(Messages.HttpNotFound);
                    return(Json(AR));
                }
                else
                {
                    throw;
                }
            }
        }
Esempio n. 13
0
        public async Task <IActionResult> SaveCategory([Bind("Id, Title, Importance, Active")] NavigationCategoryIM im)
        {
            if (!ModelState.IsValid)
            {
                AR.Setfailure(GetModelErrorMessage());
                return(Json(AR));
            }

            var model = _mapper.Map <NavigationCategory>(im);

            model.CreatedDate = DateTime.Now;
            model.CreatedBy   = User.Identity.Name;
            model.IsSys       = false;

            _context.Add(model);

            await _context.SaveChangesAsync();

            // return RedirectToAction(nameof(Index));
            AR.SetSuccess(string.Format(Messages.AlertCreateSuccess, EntityNames.MenuCategory));
            return(Json(AR));
        }
Esempio n. 14
0
        public async Task <IActionResult> Detail(int id)
        {
            var post = await _context.Posts.Include(d => d.Category).FirstOrDefaultAsync(d => d.Id == id && d.Active == true);

            if (post == null)
            {
                return(NotFound());
            }

            post.ViewCount++;
            _context.Update(post);
            await _context.SaveChangesAsync();

            var vm = new PostDetailVM
            {
                PostDetail = post,
                PostPrev   = await _context.Posts.OrderByDescending(d => d.Id).FirstOrDefaultAsync(d => d.Id < post.Id && d.Active == true),
                PostNext   = await _context.Posts.OrderBy(d => d.Id).FirstOrDefaultAsync(d => d.Id > post.Id && d.Active == true)
            };

            return(View(vm));
        }
Esempio n. 15
0
        public async Task <IActionResult> Detail(int id)
        {
            var work = await _context.Works.Include(d => d.Solution).FirstOrDefaultAsync(d => d.Id == id && d.Active);

            if (work == null)
            {
                return(NotFound());
            }

            work.ViewCount++;
            _context.Update(work);
            await _context.SaveChangesAsync();

            var vm = new WorkDetailVM
            {
                WorkDetail = work,
                WorkPrev   = await _context.Works.OrderByDescending(d => d.Id).FirstOrDefaultAsync(d => d.Id < work.Id && d.Active),
                WorkNext   = await _context.Works.OrderBy(d => d.Id).FirstOrDefaultAsync(d => d.Id > work.Id && d.Active)
            };

            return(View(vm));
        }
Esempio n. 16
0
        public async Task <IActionResult> Edit(PhotoIM article)
        {
            if (!ModelState.IsValid)
            {
                AR.Setfailure(GetModelErrorMessage());
                return(Json(AR));
            }


            try
            {
                var pm = new PageMeta
                {
                    Title       = article.SEOTitle,
                    Description = article.SEODescription,
                    Keywords    = article.SEOKeywords,
                    ModuleType  = (short)ModuleType.ARTICLE
                };


                if (article.Id > 0)
                {
                    var model = await _context.Photos.FirstOrDefaultAsync(d => d.Id == article.Id);

                    if (model == null)
                    {
                        AR.Setfailure(Messages.HttpNotFound);
                        return(Json(AR));
                    }
                    model = _mapper.Map(article, model);

                    model.UpdatedBy   = User.Identity.Name;
                    model.UpdatedDate = DateTime.Now;


                    _context.Entry(model).State = EntityState.Modified;
                    await _context.SaveChangesAsync();

                    AR.SetSuccess(string.Format(Messages.AlertUpdateSuccess, EntityNames.Photo));
                    pm.ObjectId = model.Id.ToString();
                }
                else
                {
                    var model = _mapper.Map <Photo>(article);

                    model.CreatedBy   = User.Identity.Name;
                    model.CreatedDate = DateTime.Now;


                    //model.Body = WebUtility.HtmlEncode(page.Body);

                    _context.Add(model);
                    await _context.SaveChangesAsync();

                    pm.ObjectId = model.Id.ToString();

                    AR.SetSuccess(string.Format(Messages.AlertCreateSuccess, EntityNames.Photo));
                }

                _cacheService.Invalidate("PHOTO");
                _cacheService.Invalidate("ALBUM");
                await CreatedUpdatedPageMetaAsync(_context, pm);

                return(Json(AR));
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PhotoExists(article.Id))
                {
                    AR.Setfailure(Messages.HttpNotFound);
                    return(Json(AR));
                }
                else
                {
                    throw;
                }
            }
        }
        public async Task <IActionResult> Edit([Bind("Id,Title,ImageUrl,Alias,Description,Importance,Active,SEOTitle,SEOKeywords,SEODescription")] PostCategoryIM im, int id = 0)
        {
            if (!ModelState.IsValid)
            {
                AR.Setfailure(GetModelErrorMessage());
                return(Json(AR));
            }

            if (id == 0)
            {
                var model = _mapper.Map <PostCategory>(im);
                if (User.Identity != null)
                {
                    model.CreatedBy = User.Identity.Name;
                }
                model.CreatedDate = DateTime.Now;
                _context.Add(model);

                await _context.SaveChangesAsync();

                using (LogContext.PushProperty("LogEvent", Buttons.Add))
                {
                    Serilog.Log.Information("添加博客分类:[{title}]", model.Title);
                }
                AR.SetSuccess(string.Format(Messages.AlertCreateSuccess, EntityNames.PostCategory));
                return(Json(AR));
            }

            if (id != im.Id)
            {
                AR.Setfailure("未发现此分类");
                return(Json(AR));
            }


            try
            {
                var model = await _context.PostCategories.FindAsync(id);

                model = _mapper.Map(im, model);

                if (User.Identity != null)
                {
                    model.UpdatedBy = User.Identity.Name;
                }
                model.UpdatedDate = DateTime.Now;
                _context.Update(model);
                await _context.SaveChangesAsync();

                var pm = new PageMeta
                {
                    Title       = im.SEOTitle,
                    Description = im.SEODescription,
                    Keywords    = im.SEOKeywords,
                    ModuleType  = (short)ModuleType.ARTICLECATEGORY,
                    ObjectId    = im.Alias
                };

                await CreatedUpdatedPageMetaAsync(_context, pm);

                using (LogContext.PushProperty("LogEvent", Buttons.Update))
                {
                    Serilog.Log.Information("修改博客分类:[{title}]", model.Title);
                }

                AR.SetSuccess(string.Format(Messages.AlertUpdateSuccess, EntityNames.PostCategory));
                return(Json(AR));
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PostCategoryExists(im.Id))
                {
                    AR.Setfailure("未发现此分类");
                    return(Json(AR));
                }
                else
                {
                    AR.Setfailure(string.Format(Messages.AlertUpdateFailure, EntityNames.PostCategory));
                    return(Json(AR));
                }
            }
        }
Esempio n. 18
0
        public async Task <IActionResult> Edit([Bind("Id,Title,Importance,Body,SeoName,Active,SEOTitle,SEOKeywords,SEODescription")] PageIM page)
        {
            if (!ModelState.IsValid)
            {
                AR.Setfailure(GetModelErrorMessage());
                return(Json(AR));
            }


            try
            {
                if (page.Id > 0)
                {
                    var model = await _context.Pages.SingleOrDefaultAsync(d => d.Id == page.Id);

                    model = _mapper.Map(page, model);

                    model.SeoName     = model.SeoName.ToLower();
                    model.Body        = WebUtility.HtmlEncode(page.Body);
                    model.UpdatedDate = DateTime.Now;
                    if (User.Identity != null)
                    {
                        model.UpdatedBy = User.Identity.Name;
                    }

                    _context.Update(model);
                    await _context.SaveChangesAsync();

                    AR.SetSuccess(string.Format(Messages.AlertUpdateSuccess, EntityNames.Page));
                }
                else
                {
                    var model = _mapper.Map <Page>(page);
                    model.SeoName     = model.SeoName.ToLower();
                    model.Body        = WebUtility.HtmlEncode(page.Body);
                    model.CreatedDate = DateTime.Now;
                    if (User.Identity != null)
                    {
                        model.CreatedBy = User.Identity.Name;
                    }

                    _context.Add(model);
                    await _context.SaveChangesAsync();

                    AR.SetSuccess(string.Format(Messages.AlertCreateSuccess, EntityNames.Page));
                }

                var pm = new PageMeta
                {
                    Title       = page.SEOTitle,
                    Description = page.SEODescription,
                    Keywords    = page.SEOKeywords,
                    ModuleType  = (short)ModuleType.PAGE,
                    ObjectId    = page.SeoName
                };

                await CreatedUpdatedPageMetaAsync(_context, pm);

                return(Json(AR));
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PageExists(page.Id))
                {
                    AR.Setfailure(Messages.HttpNotFound);
                    return(Json(AR));
                }
                else
                {
                    throw;
                }
            }
        }
Esempio n. 19
0
        public async Task <IActionResult> Edit(VideoIM article)
        {
            if (!ModelState.IsValid)
            {
                AR.Setfailure(GetModelErrorMessage());
                return(Json(AR));
            }


            try
            {
                if (article.Id > 0)
                {
                    var model = await _context.Videos.FirstOrDefaultAsync(d => d.Id == article.Id);

                    if (model == null)
                    {
                        AR.Setfailure(Messages.HttpNotFound);
                        return(Json(AR));
                    }
                    model = _mapper.Map(article, model);

                    model.UpdatedBy   = User.Identity.Name;
                    model.UpdatedDate = DateTime.Now;


                    _context.Entry(model).State = EntityState.Modified;
                    await _context.SaveChangesAsync();

                    AR.SetSuccess(string.Format(Messages.AlertUpdateSuccess, EntityNames.Video));
                }
                else
                {
                    var model = _mapper.Map <Video>(article);

                    model.CreatedBy   = User.Identity.Name;
                    model.CreatedDate = DateTime.Now;


                    //model.Body = WebUtility.HtmlEncode(page.Body);

                    _context.Add(model);
                    await _context.SaveChangesAsync();


                    AR.SetSuccess(string.Format(Messages.AlertCreateSuccess, EntityNames.Video));
                }



                return(Json(AR));
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!VideoExists(article.Id))
                {
                    AR.Setfailure(Messages.HttpNotFound);
                    return(Json(AR));
                }
                else
                {
                    throw;
                }
            }
        }
Esempio n. 20
0
        public async Task <IActionResult> Edit([Bind("Id,Title,Alias,Description,Importance,Active,SEOTitle,SEOKeywords,SEODescription")] JobCategoryIM im, int id = 0)
        {
            if (!ModelState.IsValid)
            {
                AR.Setfailure(GetModelErrorMessage());
                return(Json(AR));
            }

            if (id == 0)
            {
                var model = _mapper.Map <JobCategory>(im);
                model.CreatedBy   = User.Identity.Name;
                model.CreatedDate = DateTime.Now;
                _context.Add(model);

                await _context.SaveChangesAsync();

                // return RedirectToAction(nameof(Index));

                AR.SetSuccess(string.Format(Messages.AlertCreateSuccess, EntityNames.JobCategory));
                return(Json(AR));
            }

            if (id != im.Id)
            {
                AR.Setfailure("未发现此分类");
                return(Json(AR));
            }


            try
            {
                var model = await _context.JobCategories.FindAsync(id);

                model = _mapper.Map(im, model);

                model.UpdatedBy   = User.Identity.Name;
                model.UpdatedDate = DateTime.Now;
                _context.Update(model);
                await _context.SaveChangesAsync();

                //var pm = new PageMeta
                //{
                //    Title = im.SEOTitle,
                //    Description = im.SEODescription,
                //    Keywords = im.SEOKeywords,
                //    ModuleType = (short)ModuleType.ARTICLECATEGORY,
                //    ObjectId = im.Alias
                //};

                //await CreatedUpdatedPageMetaAsync(_context, pm);

                AR.SetSuccess(string.Format(Messages.AlertUpdateSuccess, EntityNames.JobCategory));
                return(Json(AR));
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!JobCategoryExists(im.Id))
                {
                    AR.Setfailure("未发现此分类");
                    return(Json(AR));
                }
                else
                {
                    AR.Setfailure(string.Format(Messages.AlertUpdateFailure, EntityNames.JobCategory));
                    return(Json(AR));
                }
            }
        }
Esempio n. 21
0
        public async Task <IActionResult> Edit(DocumentIM article)
        {
            if (!ModelState.IsValid)
            {
                AR.Setfailure(GetModelErrorMessage());
                return(Json(AR));
            }


            try
            {
                //var pm = new PageMeta
                //{
                //    Title = article.SEOTitle,
                //    Description = article.SEODescription,
                //    Keywords = article.SEOKeywords,
                //    ModuleType = (short)ModuleType.ARTICLE

                //};

                string webRootPath = _hostingEnvironment.WebRootPath;


                if (article.Id > 0)
                {
                    var model = await _context.Documents.FirstOrDefaultAsync(d => d.Id == article.Id);

                    if (model == null)
                    {
                        AR.Setfailure(Messages.HttpNotFound);
                        return(Json(AR));
                    }
                    model = _mapper.Map(article, model);

                    model.UpdatedBy   = User.Identity.Name;
                    model.UpdatedDate = DateTime.Now;

                    string filePath = webRootPath + model.FileUrl;
                    if (System.IO.File.Exists(filePath))
                    {
                        var fz = await System.IO.File.ReadAllBytesAsync(filePath);

                        model.FileSize = fz.Length;
                    }



                    _context.Entry(model).State = EntityState.Modified;
                    await _context.SaveChangesAsync();

                    AR.SetSuccess(string.Format(Messages.AlertUpdateSuccess, EntityNames.Document));
                    // pm.ObjectId = model.Id.ToString();
                }
                else
                {
                    var model = _mapper.Map <Document>(article);

                    model.CreatedBy   = User.Identity.Name;
                    model.CreatedDate = DateTime.Now;

                    string filePath = webRootPath + model.FileUrl;
                    if (System.IO.File.Exists(filePath))
                    {
                        var fz = await System.IO.File.ReadAllBytesAsync(filePath);

                        model.FileSize = fz.Length;
                    }

                    //model.Body = WebUtility.HtmlEncode(page.Body);

                    _context.Add(model);
                    await _context.SaveChangesAsync();

                    //pm.ObjectId = model.Id.ToString();

                    AR.SetSuccess(string.Format(Messages.AlertCreateSuccess, EntityNames.Document));
                }

                //await CreatedUpdatedPageMetaAsync(_context, pm);

                return(Json(AR));
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DocumentExists(article.Id))
                {
                    AR.Setfailure(Messages.HttpNotFound);
                    return(Json(AR));
                }
                else
                {
                    throw;
                }
            }
        }
Esempio n. 22
0
        public async Task <IActionResult> Index()
        {
            var vm = await _context.Pages.FirstOrDefaultAsync(d => d.SeoName == "about" && d.Active);

            if (vm == null)
            {
                return(NotFound());
            }
            vm.ViewCount++;
            _context.Update(vm);

            ViewData["PageMeta"] = await _context.PageMetas.FirstOrDefaultAsync(d => d.ObjectId == vm.SeoName && d.ModuleType == (short)ModuleType.PAGE);

            await _context.SaveChangesAsync();

            return(View(vm));
        }
Esempio n. 23
0
        public async Task <IActionResult> Edit([Bind("Id,Title,SubTitle,Thumbnail,ImageUrl,Body,Description,RelatedProducts,Products,Importance,Active,SEOTitle,SEOKeywords,SEODescription")] SolutionIM im, int id = 0)
        {
            if (!ModelState.IsValid)
            {
                AR.Setfailure(GetModelErrorMessage());
                return(Json(AR));
            }

            im.RelatedProducts = im.Products != null?string.Join("|", im.Products) : null;;

            if (id == 0)
            {
                var model = _mapper.Map <Solution>(im);

                model.CreatedBy   = User.Identity.Name;
                model.CreatedDate = DateTime.Now;
                _context.Add(model);

                await _context.SaveChangesAsync();

                // return RedirectToAction(nameof(Index));

                AR.SetSuccess(string.Format(Messages.AlertCreateSuccess, EntityNames.Solution));
                return(Json(AR));
            }
            else
            {
                if (id != im.Id)
                {
                    AR.Setfailure("未发现此分类");
                    return(Json(AR));
                }


                try
                {
                    var model = await _context.Solutions.FindAsync(id);

                    model = _mapper.Map(im, model);

                    model.UpdatedBy   = User.Identity.Name;
                    model.UpdatedDate = DateTime.Now;
                    _context.Update(model);
                    await _context.SaveChangesAsync();

                    var pm = new PageMeta
                    {
                        Title       = im.SEOTitle,
                        Description = im.SEODescription,
                        Keywords    = im.SEOKeywords,
                        ModuleType  = (short)ModuleType.SOLUTION,
                        ObjectId    = im.Id.ToString()
                    };

                    await CreatedUpdatedPageMetaAsync(_context, pm);

                    AR.SetSuccess(string.Format(Messages.AlertUpdateSuccess, EntityNames.Solution));
                    return(Json(AR));
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SolutionExists(im.Id))
                    {
                        AR.Setfailure("未发现此分类");
                        return(Json(AR));
                    }
                    else
                    {
                        AR.Setfailure(string.Format(Messages.AlertUpdateFailure, EntityNames.Solution));
                        return(Json(AR));
                    }
                }
            }
        }