Esempio n. 1
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. 2
0
        public async Task <ActionResult> EditRole(RoleIM role)
        {
            if (!ModelState.IsValid)
            {
                AR.Setfailure(GetModelErrorMessage());
                return(Json(AR));
            }

            if (role.Id > 0)
            {
                Role vRole = await _context.Roles.FindAsync(role.Id);

                if (!vRole.IsSys)
                {
                    vRole.RoleName              = role.RoleName;
                    vRole.Description           = role.Description;
                    _context.Entry(vRole).State = EntityState.Modified;
                }
                else
                {
                    AR.SetWarning("系统角色不可编辑");
                    return(Json(AR));
                }
            }
            else
            {
                var vm = _mapper.Map <Role>(role);
                _context.Add(vm);
            }

            await _context.SaveChangesAsync();

            AR.SetSuccess(String.Format(Messages.AlertCreateSuccess, EntityNames.Role));
            return(Json(AR));
        }
        public async Task <IActionResult> IsLock(int[] ids, bool isLock)
        {
            var c = await _context.PostCategories.Where(d => ids.Contains(d.Id)).ToListAsync();

            if (c == null)
            {
                AR.Setfailure(Messages.HttpNotFound);
                return(Json(AR));
            }
            foreach (var item in c)
            {
                item.Active = !isLock;
                _context.Entry(item).State = EntityState.Modified;
            }

            await _context.SaveChangesAsync();

            var logEvent = isLock ? "锁定" : "激活";

            using (LogContext.PushProperty("LogEvent", logEvent))
            {
                Serilog.Log.Information("{action}博客分类:ID[{pageIds}]", logEvent, string.Join(",", ids));
            }

            return(Json(AR));
        }
Esempio n. 4
0
        public async Task <JsonResult> IsExpand(int id)
        {
            var menu = await _context.Menus.FindAsync(id);

            if (menu != null)
            {
                menu.IsExpand = !menu.IsExpand;
                //_menuService.Update(menu);
                _context.Entry(menu).State = EntityState.Modified;
                await _context.SaveChangesAsync();


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

                AR.SetSuccess(Messages.AlertActionSuccess);
                return(Json(AR));
            }
            AR.Setfailure(Messages.AlertActionFailure);
            return(Json(AR));
        }
Esempio n. 5
0
        public async Task <JsonResult> EditMenu(NavIM menu)
        {
            if (ModelState.IsValid)
            {
                // Menu vMenu = _mapper.Map<Menu>(menu);

                var orgNav = await _context.Navigations.FindAsync(menu.Id);

                var im = _mapper.Map(menu, orgNav);


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

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


                var cacheKey = "NAVIGATION";
                _cache.Invalidate(cacheKey);
                // _menuService.ResetSort(orgMenu.CategoryId);
                //  var menus = _menuService.GetLevelMenusByCategoryId(vMenu.CategoryId);
                AR.Id = im.CategoryId;
                //// using a Model
                //string html = view.Render("Emails/Test", new Product("Apple"));

                //// using a Dictionary<string, object>
                //var viewData = new Dictionary<string, object>();
                //viewData["Name"] = "123456";

                //string html = view.Render("Emails/Test", viewData);
                //AR.Data = await _viewRenderService.RenderToStringAsync("_MenuList", menus);

                var pm = new PageMeta
                {
                    Title       = menu.SEOTitle,
                    Description = menu.SEODescription,
                    Keywords    = menu.SEOKeywords,
                    ModuleType  = (short)ModuleType.MENU,
                    ObjectId    = menu.Url
                };

                await CreatedUpdatedPageMetaAsync(_context, pm);


                AR.SetSuccess("已成功保存菜单");
                return(Json(AR));
            }

            AR.Setfailure("编辑菜单失败");
            return(Json(AR));
        }
        public async Task <IActionResult> IsLock(int[] ids, bool isLock)
        {
            var c = await _context.JobCategories.Where(d => ids.Contains(d.Id)).ToListAsync();

            if (c == null)
            {
                AR.Setfailure(Messages.HttpNotFound);
                return(Json(AR));
            }
            foreach (var item in c)
            {
                item.Active = isLock ? false : true;
                _context.Entry(item).State = EntityState.Modified;
            }

            await _context.SaveChangesAsync();

            return(Json(AR));
        }
Esempio n. 7
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;
                }
            }
        }
Esempio n. 8
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. 9
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;
                }
            }
        }