public async Task <IActionResult> Edit(string id, [Bind("Id,Name,Description,Price")] GoodsViewModel good) { if (id != good.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(good); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!GoodExists(good.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(good)); }
/// <summary> /// 搜索物品选择数据信息 /// </summary> /// <param name="webModel">列表页视图Model</param> /// <param name="context">数据库连接上下文对象</param> /// <returns></returns> public async Task <GoodsViewModel> SearchGoodsAsync(GoodsViewModel webModel, ApplicationDbContext context) { try { //Source Data List var list = await StatisticsRepository.GetListAsync(webModel, context); //Return Data List var dataList = new List <GoodsData>(); if (list != null && list.Any()) { dataList.AddRange(list.Select(item => new GoodsData { Id = item.StudentId.ToString(), Name = item.StudentName, GoodsId = item.GoodsId.ToString(), GoodsName = item.GoodsName, Size = item.Size, DateTime = item.ChosenTime, Remark = item.Remark.Length > 20 ? item.Remark.Substring(0, 20) : item.Remark })); } webModel.GoodsList = dataList; webModel.Total = await StatisticsRepository.GetListCountAsync(webModel, context); } catch (Exception ex) { _logger.LogError("获取物品选择列表失败:{0},\r\n内部错误信息:{1}", ex.Message, ex.InnerException.Message); } return(webModel); }
// // GET: /Account/Cart/?userId=xxxx&bookId=xxxx //public ActionResult Cart(string userId, string bookId) //{ // using(var context = new OnionContext()) // { // context.preorders.Remove(context.preorders.Where(x => x.BOOKID == bookId && x.CUSTOMERID == userId).FirstOrDefault()); // int res = context.SaveChanges(); // } // return View(); //} // // GET: /Account/Star/?userId=xxxx public ActionResult Star() { var starVM = new GoodsViewModel(); string userId = User.Identity.GetUserId(); using (var context = new OnionContext()) { var query = from b in context.stars join c in context.books on b.BOOKID equals c.BOOKID join d in context.pictures on c.BOOKID equals d.BOOKID join e in context.writes on c.BOOKID equals e.BOOKID join f in context.authors on e.AUTHORID equals f.AUTHORID where b.CUSTOMERID == userId select new Goods() { PICTURE = d.PATH, NAME = c.NAME, PRICE = c.PRICE * c.DISCOUNT, PUBLISHER = c.PUBLISHER, AUTHOR = f.NAME, BOOKID = b.BOOKID, }; starVM.GOODS = new System.Collections.Generic.List <Goods>(query.ToList()); } return(View(starVM)); }
/// <summary> /// 根据搜索条件获取物品预定信息 /// </summary> /// <param name="webModel">列表页视图模型</param> /// <param name="context">数据库上下文对象</param> /// <returns></returns> public static async Task <List <GoodsInfo> > GetListAsync(GoodsViewModel webModel, ApplicationDbContext context) { if (string.IsNullOrEmpty(webModel.SName) && string.IsNullOrEmpty(webModel.SGoodsName) && string.IsNullOrEmpty(webModel.SDate)) { return(await context.Set <GoodsInfo>().AsNoTracking().Skip(webModel.Start).Take(webModel.Limit).OrderByDescending(i => i.ChosenTime).ToListAsync()); } else { IQueryable <GoodsInfo> goodsInfos = context.GoodsInfo.AsQueryable(); var predicate = PredicateBuilder.New <GoodsInfo>(); //学生姓名 if (!string.IsNullOrEmpty(webModel.SName)) { predicate = predicate.And(i => i.StudentName == webModel.SName); } //物品名称 if (!string.IsNullOrEmpty(webModel.SGoodsName)) { predicate = predicate.And(i => i.GoodsName.Contains(webModel.SGoodsName)); } //物品选择时间 if (!string.IsNullOrEmpty(webModel.SDate)) { predicate = predicate.And(i => i.ChosenTime.ToString("yyyy-MM-dd") == webModel.SDate); } return(await goodsInfos.AsExpandable().Where(predicate).ToListAsync()); } }
private async void Button_Clicked(object sender, EventArgs e) { GoodsDetailViewModel gdvm = BindingContext as GoodsDetailViewModel; if (gdvm.GoodsModel.User.Name == App.StaticUser.Name) { await App.GoodsManager.DeleteGoodsTaskAsync(gdvm.GoodsModel); GoodsViewModel.refresh(); DependencyService.Get <IToastService>().LongAlert("删除商品成功!"); await Navigation.PopAsync(); } else { if (App.StaticUser.TomatoPoints >= gdvm.GoodsModel.Price) { App.StaticUser.TomatoPoints -= gdvm.GoodsModel.Price; await App.UserManager.ModifyUserTaskAsync(App.StaticUser); DependencyService.Get <IToastService>().LongAlert("购买商品成功!"); await Navigation.PopAsync(); } else { DependencyService.Get <IToastService>().LongAlert("番茄点不足,不能购买!"); } } }
public ActionResult Cart() { var cartVM = new GoodsViewModel(); using (var context = new OnionContext()) { string userId = User.Identity.GetUserId(); var query = from b in context.preorders join c in context.books on b.BOOKID equals c.BOOKID join d in context.pictures on c.BOOKID equals d.BOOKID where b.CUSTOMERID == userId select new Goods() { PICTURE = d.PATH, NAME = c.NAME, AMOUNT = b.AMOUNT, PRICE = c.PRICE * c.DISCOUNT, BOOKID = b.BOOKID, }; cartVM.GOODS = new System.Collections.Generic.List <Goods>(query.ToList()); } cartVM.calcTotal(); return(View(cartVM)); }
/// <summary> /// 根据搜索条件获取物品信息 /// </summary> /// <param name="webModel">列表页视图模型</param> /// <param name="context">数据库上下文对象</param> /// <returns></returns> public static async Task <List <Goods> > GetListAsync(GoodsViewModel webModel, ApplicationDbContext context) { if (string.IsNullOrEmpty(webModel.SName) && string.IsNullOrEmpty(webModel.SId) && webModel.SEnable == -1) { return(await context.Set <Goods>().AsNoTracking().Skip(webModel.Start).Take(webModel.Limit).OrderByDescending(i => i.CreatedOn).ToListAsync()); } else { IQueryable <Goods> goods = context.Goods.AsQueryable(); var predicate = PredicateBuilder.New <Goods>(); //物品名称 if (!string.IsNullOrEmpty(webModel.SName)) { predicate = predicate.And(i => i.Name == webModel.SName); } //物品编号 if (!string.IsNullOrEmpty(webModel.SId)) { predicate = predicate.And(i => i.Id == Convert.ToInt64(webModel.SId)); } //是否启用 if (webModel.SEnable != -1) { bool flag = webModel.SEnable == 1; predicate = predicate.And(i => i.IsEnabled == flag); } return(await goods.AsExpandable().Where(predicate).ToListAsync()); } }
public List <CategoryViewModel> GetGoodsCategoryInfo() { var categories = dao.GetLevel1Categories(); var goodsCategory = dao.GetGoodsCategoryInfo(); var categoriesList = new List <CategoryViewModel>(); foreach (DataRow row in categories.Rows) { var goodsList = new List <GoodsViewModel>(); DataRow[] goodsRows = goodsCategory.Select("categoryid=" + row["CategoryID"]); foreach (DataRow goodsRow in goodsRows) { var goods = new GoodsViewModel() { GoodsID = (int)goodsRow["goodsid"], ShortName = (string)goodsRow["shortname"], }; goodsList.Add(goods); } var category = new CategoryViewModel() { CategoryID = (int)row["CategoryID"], CategoryName = (string)row["CategoryName"], GoodsList = goodsList }; categoriesList.Add(category); } return(categoriesList); }
public IActionResult Create(GoodsViewModel goodsViewModel) { goodsTable.Add(new Goods(goodsViewModel)); marketContext.SaveChanges(); return(View()); }
public ActionResult BrowseGoodsAll() { GoodsGroupViewModel ggvm = new GoodsGroupViewModel(); ggvm.Goods = new List <GoodsViewModel>(); ggvm.GoodsClass = new List <GoodsClassViewModel>(); foreach (Goods Gdb in (db.Goods.Where(o => o.GdsCount != 0).OrderByDescending(o => o.GdsID).ToList())) { GoodsViewModel gvm = new GoodsViewModel() { CaseID = Gdb.CaseID, GdsName = Gdb.GdsName, MemberID = Gdb.Cases.MemberID, GdsCount = Gdb.GdsCount, NickName = Gdb.Cases.Member.NickName, StatusName = db.CaseStatus.Find(db.Cases.Find(Gdb.CaseID).StatusID).StatusName, CaseTitle = Gdb.Cases.CaseTitle, GdsClass = Gdb.GdsSubClass.GoodsClass.GdsClass }; ggvm.Goods.Add(gvm); } IQueryable <string> gc = db.GoodsClass.Select(x => x.GdsClass).Distinct(); foreach (string GCdb in gc) { GoodsClassViewModel gcvm = new GoodsClassViewModel(); gcvm.GdsClass = GCdb; ggvm.GoodsClass.Add(gcvm); } return(View(ggvm)); }
public ActionResult Edit(int id) { using (var db = new SmDbContext()) { var entity = db.Goods.First(x => x.Id == id); var model = new GoodsViewModel { Id = entity.Id, Brand = entity.Brand, Description = entity.Description, GoodsCategoryId = entity.GoodsCategoryId, GoodsSubCategoryId = entity.GoodsSubCategoryId, Name = entity.Name, Price = entity.Price, ProductCode = entity.ProductCode, Quantity = entity.Quantity }; var list = db.GoodsSubCategories.Where(x => x.GoodsCategoryId == entity.GoodsCategoryId).Select(x => new SelectListItem { Value = x.Id.ToString(), Text = x.Name, }).OrderBy(x => x.Text).ToList(); ViewBag.GoodsSubCategories = list; return(View(model)); } }
/// <summary> /// 搜索物品信息 /// </summary> /// <param name="webModel">列表页视图Model</param> /// <param name="context">数据库连接上下文对象</param> /// <returns></returns> public async Task <GoodsViewModel> SearchGoodsAsync(GoodsViewModel webModel, ApplicationDbContext context) { try { //Source Data List var list = await AdmissionRepository.GetListAsync(webModel, context); //Return Data List var dataList = new List <GoodsData>(); if (list != null && list.Any()) { dataList.AddRange(list.Select(item => new GoodsData { Id = item.Id.ToString(), Name = item.Name, IsEnabled = item.IsEnabled, Size = item.Size, ImageSrc = item.ImageSrc, Description = !string.IsNullOrEmpty(item.Description) && item.Description.Length > 20 ? item.Description.Substring(0, 20) + "..." : item.Description })); } webModel.GoodsList = dataList; webModel.Total = await AdmissionRepository.GetListCountAsync(webModel, context); } catch (Exception ex) { _logger.LogError("获取物品信息列表失败:{0},\r\n内部错误信息:{1}", ex.Message, ex.InnerException.Message); } return(webModel); }
public ActionResult Index(GoodsViewModel vm) { var predicate = PredicateBuilder.New <Good>(); foreach (var filter in vm.Filters) { var pred = PredicateBuilder.New <Good>(); pred.And(x => filter.IsChecked); pred.And(x => x.Price >= filter.From); pred.And(x => x.Price <= filter.To); predicate.Extend(pred, PredicateOperator.Or); } var vmm = new GoodsViewModel { Filters = new List <PriceFilter> { new PriceFilter { From = 1000, To = 2000 }, new PriceFilter { From = 2000, To = 4000 }, new PriceFilter { From = 4000, To = 10000 } }, Goods = repo.FindBy(predicate) }; return(View(vmm)); }
private HotPageData <List <GoodsViewModel> > GetGoodsList(HQRequestHeader header, HotGoodsSearchCondition condition) { HotPageData <List <HotGoodsModel> > pageData = GoodsProviderFactory.GetInstance(header.platType).GetGoodsList(condition, out string errMsg); HotPageData <List <GoodsViewModel> > pageViewData = new HotPageData <List <GoodsViewModel> >(); pageViewData.PageCount = pageData.PageCount; pageViewData.PageIndex = pageData.PageIndex; pageViewData.PageSize = pageData.PageSize; pageViewData.Total = pageData.Total; List <GoodsViewModel> viewList = new List <GoodsViewModel>(); foreach (HotGoodsModel goodsInfo in pageData.Rows) { GoodsViewModel viewInfo = new GoodsViewModel(); viewInfo.couponPrice = goodsInfo.CouponDiscount.ToString("F2"); viewInfo.earnMoney = goodsInfo.PromotionAmount.ToString("F2");//????要乘一个百分比 viewInfo.finalPrice = goodsInfo.CouponedPrice.ToString("F2"); viewInfo.goodsId = goodsInfo.GoodsId; viewInfo.goodsIntro = goodsInfo.GoodsDesc; viewInfo.goodsPrice = goodsInfo.MinGroupPrice.ToString("F2"); viewInfo.imgs = goodsInfo.GoodsGalleryUrls.ToArray(); viewInfo.imgSrc = goodsInfo.GoodsThumbnailUrl; viewInfo.isFav = false;//???赋值 viewInfo.platform = header.platType; viewInfo.salesVolume = goodsInfo.SoldQuantity; viewInfo.title = goodsInfo.GoodsName; viewList.Add(viewInfo); } pageViewData.Rows = viewList; return(pageViewData); }
public GoodsViewModel GetGoods(int category = -1, string search = "", int pageSize = 25, int page = 1) { var viewModel = new GoodsViewModel(); viewModel.Goods = this._goodService.GetGoods(category, out var totalCount, search, pageSize, page); viewModel.TotalCount = totalCount; return(viewModel); }
public Goods(GoodsViewModel viewModel) { Name = viewModel.Name; Price = viewModel.Price; CountryId = 1; CurrencyId = 1; Images = viewModel.Images.Map(f => new GoodsFile(f)); ThumbnailPath = new GoodsFile(viewModel.Thumbnail).Path; }
public IActionResult Create(GoodsViewModel model) { var goods = new Goods(0, model.Idx, model.Name, model.GoodsCatId, model.DimensionId, model.ProviderId, model.Val, model.ValDelivered, model.Price, model.Delivery, model.ImpPeriod, model.ImpTime, model.Weight, null, null, null, 0, 0); _repository.Create(goods); return(RedirectToAction("Index")); }
public IActionResult Edit(GoodsViewModel model) { var goods = new Goods(model.Id, model.Idx, model.Name, model.GoodsCatId, model.DimensionId, model.ProviderId, model.Val, model.ValDelivered, model.Price, model.Delivery, model.ImpPeriod, model.ImpTime, model.Weight, null, null, null, 0, 0); if (_repository.Update(goods)) { return(RedirectToAction("Index")); } return(BadRequest()); }
//TEST public PartialViewResult GetCategoryList(string category) { GoodsViewModel model = new GoodsViewModel { Goods = goods.FindAll(x => x.GoodCategory == category), Pages = new PageLinksModel { CurrentPage = 1, TotalItems = goods.Count(), CountPerPage = pagesize } }; return(PartialView(model)); }
public PartialViewResult GetGoodsList(int id = 1) { GoodsViewModel model = new GoodsViewModel { Goods = goods.Skip((id - 1) * pagesize).Take(pagesize), Pages = new PageLinksModel { CurrentPage = id, TotalItems = goods.Count(), CountPerPage = pagesize } }; return(PartialView(model)); }
public ActionResult Index(int id = 1) { GoodsViewModel model = new GoodsViewModel { Goods = goods.Skip((id - 1) * pagesize).Take(pagesize), Pages = new PageLinksModel { CurrentPage = id, TotalItems = goods.Count(), CountPerPage = pagesize } }; return(View(model)); }
private string UploadedFile(GoodsViewModel model) { string uniqueFileName = null; if (model.Image != null) { string uploadsFolder = Path.Combine(webHostEnvironment.WebRootPath, "images"); uniqueFileName = Guid.NewGuid().ToString() + "_" + model.Image.FileName; string filePath = Path.Combine(uploadsFolder, uniqueFileName); using (var fileStream = new FileStream(filePath, FileMode.Create)) { model.Image.CopyTo(fileStream); } } return(uniqueFileName); }
public ActionResult SaveAjax(GoodsViewModel model) { if (!ModelState.IsValid) { return(PartialView("CreatePartial", model)); } try { SaveModel(model); return(SuccessJson()); } catch (Exception ex) { ModelState.AddModelError("Name", ex); return(PartialView("CreatePartial", model)); } }
private async void Button_Clicked(object sender, EventArgs e) { AddGoodsViewModel agvm = BindingContext as AddGoodsViewModel; agvm.GoodsModel.Type = comboBox.SelectedItem.ToString(); agvm.GoodsModel.Date = DateTime.Now.ToString("yyyy-MM-dd HH:mm"); agvm.GoodsModel.Uri = gm.Uri; agvm.GoodsModel.UserId = App.StaticUser.UserId; Random ran = new Random(); long RandKey = ran.Next(0, 9999); agvm.GoodsModel.Id = RandKey; await App.GoodsManager.AddGoodsTaskAsync(agvm.GoodsModel); GoodsViewModel.refresh(); DependencyService.Get <IToastService>().LongAlert("增加商品成功!"); await Navigation.PopAsync(); }
public async Task <IActionResult> SearchGoods(string search) { GoodsViewModel webModel = JsonUtility.ToObject <GoodsViewModel>(search); webModel = await _service.SearchGoodsAsync(webModel, _context); //Search Or Init bool flag = string.IsNullOrEmpty(webModel.SName) && string.IsNullOrEmpty(webModel.SGoodsName) && string.IsNullOrEmpty(webModel.SDate); var returnData = new { data = webModel.GoodsList, limit = webModel.Limit, page = flag ? webModel.Page : 1, total = webModel.Total }; return(Json(returnData)); }
// GET: Admin/Goods public ActionResult BrowseGoodsAll() { List <GoodsViewModel> gvmList = new List <GoodsViewModel>(); foreach (var gs in (GoodsDB.GetAll()).ToList()) { GoodsViewModel gvm = new GoodsViewModel() { CaseID = gs.CaseID, CaseTitle = gs.Cases.CaseTitle, MemberName = gs.Cases.Member.LastName + gs.Cases.Member.FirstName, StartDateTime = gs.Cases.StartDateTime, EndDateTime = gs.Cases.EndDateTime, GdsCount = gs.GdsCount, StatusName = gs.Cases.CaseStatus.StatusName }; gvmList.Add(gvm); } return(IL.InterceptionLogin(View(gvmList), Session["AdminID"])); }
private void SaveModel(GoodsViewModel model) { using (var db = new SmDbContext()) { var entity = db.Goods.FirstOrDefault(x => x.Id == model.Id); if (entity == null) { entity = new Goods(); db.Goods.Add(entity); } entity.Brand = model.Brand; entity.Description = model.Description; entity.GoodsCategoryId = model.GoodsCategoryId; entity.GoodsSubCategoryId = model.GoodsSubCategoryId; entity.Name = model.Name; entity.Price = model.Price; entity.ProductCode = model.ProductCode; db.SaveChanges(); } }
public ActionResult GoodsList(string title = "", int pageIndex = 1) { //然后设置每页显示的条数 int pageSize = 12; //根据商品的编号排序,然后contains模糊查询 ,然后通过skip和take取得数据 var goods = db.Goods.Where(g => g.GoodsName.Contains(title)).OrderBy(g => g.GoodsId).Skip((pageIndex - 1) * pageSize).Take(pageSize); //构建视图模型,填充商品列表和分页的数据 var goodsViewModel = new GoodsViewModel { Goods = goods, PageInfo = new PageInfo { PageSize = pageSize, PageIndex = pageIndex, Count = db.Goods.Where(g => g.GoodsName.Contains(title)).Count() } }; //返回json数据 return(Json(goodsViewModel, JsonRequestBehavior.AllowGet)); }
public ActionResult Index() { GoodsViewModel vm = new GoodsViewModel { Goods = repo.GetAll(), Filters = new List <PriceFilter> { new PriceFilter { From = 1000, To = 2000 }, new PriceFilter { From = 2000, To = 4000 }, new PriceFilter { From = 4000, To = 10000 } } }; return(View(vm)); }
public ActionResult Goodsneed() { GoodsGroupViewModel ggvm = new GoodsGroupViewModel(); ggvm.Goods = new List <GoodsViewModel>(); ggvm.GoodsClass = new List <GoodsClassViewModel>(); var q = (from o in db.Cases join g in db.Goods on o.CaseID equals g.CaseID where o.StatusID == 5 orderby g.GdsID descending select g).ToList(); foreach (Goods Gdb in (q)) { GoodsViewModel gvm = new GoodsViewModel() { CaseID = Gdb.CaseID, GdsName = Gdb.GdsName, MemberID = Gdb.Cases.MemberID, GdsCount = Gdb.GdsCount, NickName = Gdb.Cases.Member.NickName, StatusName = db.CaseStatus.Find(db.Cases.Find(Gdb.CaseID).StatusID).StatusName, CaseTitle = Gdb.Cases.CaseTitle, GdsClass = Gdb.GdsSubClass.GoodsClass.GdsClass }; ggvm.Goods.Add(gvm); } IQueryable <string> gc = db.GoodsClass.Select(x => x.GdsClass).Distinct(); foreach (string GCdb in gc) { GoodsClassViewModel gcvm = new GoodsClassViewModel(); gcvm.GdsClass = GCdb; ggvm.GoodsClass.Add(gcvm); } return(View(ggvm)); }