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; } } }
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))); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Title,Summary,Body,Author,Description,Keywords,Thumbnail,Pubdate,ViewCount,Active,CategoryId,CreatedBy,CreatedDate,UpdatedBy,UpdatedDate")] Article article) { if (id != article.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(article); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ArticleExists(article.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["CategoryId"] = new SelectList(_context.ArticleCategories, "Id", "Alias", article.CategoryId); return(View(article)); }
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> 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)); }
public void Update(Role role) { _db.Update(role); // _db.Entry(role).State = EntityState.Modified; _db.SaveChanges(); // _unitOfWork.GetRepository<Role>().Update(role); //_unitOfWork.SaveChanges(); }
/// <summary> /// 按分类重设排序 /// </summary> /// <param name="categoryId"></param> public void ResetSort(int categoryId) { var menuList = _db.Menus.Include(d => d.InverseParent).Where(d => d.CategoryId == categoryId); //_unitOfWork.GetRepository<Menu>().GetMany(predicate: d => d.CategoryId == categoryId, include: d => d.Include(m => m.InverseParent)); var list = menuList.Where(m => m.ParentId == null).OrderBy(m => m.Importance) .SelectDeep <Menu>(m => m.InverseParent.OrderBy(g => g.Importance)); int i = 0; foreach (var item in list) { var menu = GetById(item.Id); menu.Importance = i; _db.Update(menu); i++; } _db.SaveChanges(); }
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; } } }
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; } } }
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); }
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)); }
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)); }
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)); }
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)); } } } }
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)); } } }
public void Update(User user) { _db.Update(user); _db.SaveChanges(); }
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)); } } }
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)); }
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; } } }