public IActionResult Index(int id) { Models.EditViewModel viewModel = new Models.EditViewModel(); //获取频道数据 var channelRepository = _unitOfWork.GetRepository <Entity.m_CmsChannel>(); viewModel.ChannelListData = channelRepository.Query() .OrderBy(q => q.SortCount) .Select(q => new Models.ChannelDataModel() { AppendTime = q.AppendTime.Value, ChannelId = q.ChannelId.Value, ChannelName = q.ChannelName, RemarkText = q.RemarkText, SortCount = q.SortCount.Value, StateCode = q.StateCode.Value }) .ToList(); //获取文章内容数据 int accountId = HttpContext.Session.GetInt32("AccountId").GetValueOrDefault(0); var repository = _unitOfWork.GetRepository <Entity.m_CmsContents>(); var accountRepository = _unitOfWork.GetRepository <m_Account>(); viewModel.ContentsData = repository.Query() .Join(accountRepository.Query(), c => c.AccountId, account => account.AccountId, (c, account) => new { c, account }) .Join(channelRepository.Query(), ca => ca.c.ChannelId, channel => channel.ChannelId, (ca, channel) => new Models.ContentsDataModel() { AccountId = ca.c.AccountId.Value, AnswerCount = ca.c.AnswerCount.Value, ChannelId = ca.c.ChannelId.Value, ChannelName = channel.ChannelName, ContentsId = ca.c.ContentsId.Value, HeadUrl = ca.account.HeadUrl, LastTime = ca.c.LastTime.Value, NickName = ca.account.NickName, PlusCount = ca.c.PlusCount.Value, PostTime = ca.c.PostTime.Value, ReadCount = ca.c.ReadCount.Value, StateCode = ca.c.StateCode.Value, Title = ca.c.Title, Contents = ca.c.Contents }) .Where(q => q.StateCode == 1 && q.ContentsId == id && q.AccountId == accountId) .OrderByDescending(q => q.ContentsId) .FirstOrDefault(); return(View(viewModel)); }
public IActionResult Index(int id) { Models.EditViewModel viewModel = new Models.EditViewModel(); //获取频道数据 var apiResult = HttpCore.HttpGet($"/api/CMS/Channel"); if (apiResult.Code == 0) { viewModel.ChannelListData = JsonConvert.DeserializeObject <List <Models.ChannelDataModel> >(apiResult.Data.ToString()); } //获取文章内容数据 int accountId = HttpContext.Session.GetInt32("AccountId").GetValueOrDefault(0); apiResult = HttpCore.HttpGet($"/api/CMS/Contents/user/{accountId}/{id}"); if (apiResult.Code == 0) { viewModel.ContentsData = JsonConvert.DeserializeObject <Models.ContentsDataModel>(apiResult.Data.ToString()); } return(View(viewModel)); }
//Method called after Offer to edit is selected public ActionResult Edit(SelectOfferViewModel model) { var userId = User.Identity.GetUserId(); var getUser = _context.Users.Include(c => c.Merchant).FirstOrDefault(c => c.Id == userId); var getOffer = _context.Offers .Include(c => c.Merchant) .Include(c => c.Categories) .FirstOrDefault(c => c.OfferId == model.OfferId); var viewModel = new Models.EditViewModel { offer = new MerchantCreateOfferViewModel { OfferId = getOffer.OfferId, //CouponDurationInMonths = getOffer.CouponDurationInMonths, //CouponPrice = getOffer.CouponPrice, DiscountRate = getOffer.DiscountRate, MerchantID = getOffer.Merchant.MerchantID, OfferBegins = getOffer.OfferBegins, OfferEnds = getOffer.OfferEnds, OfferDetails = getOffer.OfferDetails, OfferName = getOffer.OfferName, TotalOffer = getOffer.TotalOffer, Categories = new List <Category>(), //Instantiate the category list } }; //Sets the categories viewModel.offer.Categories = _context.Categories.ToList(); viewModel.OfferCategories = new List <Category>(); viewModel.OfferCategories = getOffer.Categories.ToList(); Session["SelectedCategories"] = getOffer.Categories; return(View("Edit", viewModel)); }
public ActionResult Edit() { EditViewModel model = null; try { string id = User.Identity.GetUserId(); using (var db = new StationCADDb()) { var user = db.Users.Include("Profile").Where(x => x.Id == id).FirstOrDefault(); if (user != null) model = new Models.EditViewModel(user); } } catch(Exception ex) { string msg = string.Format("An error occured in ManageController.Edit(string id). Message: {0}", ex.Message); LogException(msg, ex); return View("Error"); } if (model == null) { ViewBag.errorMessage = "Unable to find user data."; // Log them out for safety... AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie); return RedirectToAction("Index", "Home"); } else { return View(model); } }
public ActionResult Save(Models.EditViewModel editInfo) { AjaxResult result = new AjaxResult(); if (ModelState.IsValid) { bool isEdit = false; TransactionManager.Excute(delegate { Blog blogInfo = MapperManager.Map <Blog>(editInfo); if (!string.IsNullOrEmpty(editInfo.HexId)) { isEdit = true; blogInfo.Id = Convert.ToInt64(Helper.FromHex(editInfo.HexId)); } DbContextManager dbContext = new DbContextManager(); string[] imgList = WebHelper.GetHtmlImageUrlList(blogInfo.ContentHtml); if (imgList.Length > 0) { blogInfo.ImgUrl = string.Join(",", imgList); } if (!blogInfo.IsMarkDown) { blogInfo.Content = HttpUtility.HtmlEncode(blogInfo.ContentHtml); } if (blogInfo.IsPublish) { blogInfo.PublishDate = DateTime.Now; } List <string> tagList = new List <string>(); if (!string.IsNullOrEmpty(editInfo.PersonTags)) { int fakeId = 0; Dictionary <string, string> dicts = JsonConvert.DeserializeObject <Dictionary <string, string> >(editInfo.PersonTags); foreach (KeyValuePair <string, string> item in dicts) { if (!string.IsNullOrEmpty(item.Value)) { if (item.Key.Contains("newData")) { string value = item.Value.Trim(); BlogTag tag = _tagService.GetEntity(b => b.Name == value); if (tag == null) { tag = new BlogTag() { Id = fakeId++, Name = value, }; if (UserContext.LoginUser != null) { tag.UserId = UserContext.LoginUser.Id; } FillAddModel(tag); tag = _tagService.Insert(tag); // tag = dbContext.Add(tag); } tagList.Add(tag.Id.ToString()); } else if (!string.IsNullOrEmpty(item.Key)) { tagList.Add(item.Key); } } } } blogInfo.BlogTags = string.Join(",", tagList); if (isEdit) { _blogService.UpdateEntityFields(blogInfo, "Title", "ContentHtml", "Content", "TypeId", "CatId", "PersonTop", "Private", "Publish", "CanCmt", "MarkDown", "BlogTags", "PublishDate"); } else { blogInfo = FillAddModel(blogInfo); blogInfo = _blogService.Insert(blogInfo); } result.Resultdata = "/article/" + blogInfo.UserName + "/" + blogInfo.HexId; }); } else { result.Success = false; foreach (var key in ModelState.Keys) { var modelstate = ModelState[key]; if (modelstate.Errors.Any()) { result.Message = modelstate.Errors.FirstOrDefault().ErrorMessage; break; } } } return(Json(result, JsonRequestBehavior.AllowGet)); }