public ActionResult EditOnPost(EditDiscoveryViewModel editDiscovery) { var result = new DataJsonResult(); Models.Discovery model = new Models.Discovery(); if (editDiscovery.Id != Guid.Empty) { model = _currencyService.GetSingleById <Models.Discovery>(editDiscovery.Id); } model.Title = editDiscovery.Title; model.Source = editDiscovery.Source; model.Content = editDiscovery.Content; model.Blurb = editDiscovery.Blurb; model.Author = editDiscovery.Author; model.Id = _discoveryService.SaveDiscovery(model, editDiscovery.Goods); if (model.Id != Guid.Empty) { //添加图片关联关系 _storageFileService.ReplaceFile(model.Id, DiscoveryModule.Key, DiscoveryModule.DisplayName, editDiscovery.DiscoveryImages, DiscoveryImages); } else { result.ErrorMessage = "保存失败"; } return(Json(result)); }
public ActionResult Edit(Guid?id = null) { Models.Discovery model = new Models.Discovery(); if (id != null && id != Guid.Empty) { model = _currencyService.GetSingleById <Models.Discovery>(id); } ViewBag.RelationGoods = _discoveryService.GetDiscoveryRelationGoods(model.Id); return(View(model)); }
public DiscoveryModel(Models.Discovery model) { Id = model.Id; Title = model.Title; Content = model.Content; CreateTime = model.CreateTime; ReadNum = model.ReadNum; var fileService = HostConstObject.Container.Resolve <IStorageFileService>(); var mainImage = fileService.GetFiles(model.Id, DiscoveryModule.Key, "DiscoveryImages").FirstOrDefault(); MainImage = mainImage?.Simplified(); }
public Guid SaveDiscovery(Models.Discovery model, List <Guid> goodsIds) { bool result; using (var dbContext = new DiscoveryDbContext()) { model.LastUpdateTime = DateTime.Now; //新增 if (model.Id == Guid.Empty) { model.Id = KeyGenerator.GetGuidKey(); model.CreateTime = DateTime.Now; var currentUser = _userContainer.CurrentUser; model.CreateUserId = currentUser.Id; model.CreateName = currentUser.UserName; model.Status = DiscoveryStatus.Normal; dbContext.Discoveries.Add(model); } else//编辑 { //删除商品关联 var goods = dbContext.DiscoveryGoodsRelations.Where(x => x.DiscoveryId == model.Id).ToList(); goods.ForEach(m => dbContext.Entry(m).State = EntityState.Deleted); dbContext.Discoveries.Attach(model); dbContext.Entry(model).State = EntityState.Modified; } //关联商品 foreach (var goodsId in goodsIds) { DiscoveryGoodsRelation relation = new DiscoveryGoodsRelation { Id = KeyGenerator.GetGuidKey(), DiscoveryId = model.Id, GoodsId = goodsId }; dbContext.DiscoveryGoodsRelations.Add(relation); } result = dbContext.SaveChanges() > 0; } if (!result) { return(Guid.Empty); } return(model.Id); }