public virtual async Task <DeleteStatusModel> DeleteAndSaveAsyn(Guid id) { var result = new DeleteStatusModel() { DeleteSatus = true, Message = "删除操作成功!" }; var hasIstance = await HasInstanceAsyn(id); if (!hasIstance) { result.DeleteSatus = false; result.Message = "不存在所指定的数据,无法执行删除操作!"; } else { var tobeDeleteItem = await GetSingleAsyn(id); try { _EntitiesContext.Set <T>().Remove(tobeDeleteItem); _EntitiesContext.SaveChanges(); } catch (DbUpdateException ex) { result.DeleteSatus = false; result.Message = ex.Message; } } return(result); }
public async Task <IActionResult> Delete(Guid id) { var status = new DeleteStatusModel() { DeleteSatus = true, Message = "数据删除成功" }; try { await _boService.DeleteAndSaveAsyn(id); } catch { status.DeleteSatus = false; status.Message = "删除操作出现意外,主要原因是关联数据没有处理干净活者是其他原因。"; } return(Json(status)); }
/// <summary> /// 删除角色组 /// </summary> /// <param name="id"></param> /// <returns></returns> public async Task <DeleteStatusModel> DeletBoStatus(Guid id) { var bo = await _roleManager.FindByIdAsync(id.ToString()); var status = new DeleteStatusModel() { DeleteSatus = true, Message = "数据删除成功" }; try { await _roleManager.DeleteAsync(bo); } catch { status.DeleteSatus = false; status.Message = "删除操作出现意外,主要原因是关联数据没有处理干净活者是其他原因。"; } return(status); }
public async Task <IActionResult> CancelSettled() { var status = new DeleteStatusModel(); var username = User.Identity.Name; var user = await _UserManager.FindByNameAsync(username); var bo = _ShopSelltedRepository.GetSingleBy(x => x.BelongToUserID == user.Id); if (bo != null) { var imgs = await _ImageRepository.FindByAsyn(x => x.RelevanceObjectID == bo.ID); foreach (var img in imgs) { await _ImageRepository.DeleteAndSaveAsyn(img.ID); } status = await _ShopSelltedRepository.DeleteAndSaveAsyn(bo.ID); status.Message = "撤销成功"; } return(Json(status)); }
/// <summary> /// 删除数据,将删除操作的结果加载到 DeleteStatus 对象,然后转成 json 数据返回给前端。 /// </summary> /// <param name="id">待删除的对象 ID 属性值</param> /// <returns>将删除操作处理的结果转为 json 数据返回到前端,供前端根据情况处理</returns> public async Task <IActionResult> Delete(Guid id) { var status = new DeleteStatusModel(); var image = await _ImageRepository.GetSingleAsyn(id); if (image == null) { var goods = await _BoRepository.FindByAsyn(x => x.ID == id); var shopcar = await _ShopCarGoodsItemRepository.FindByAsyn(x => x.GoodsName == goods.FirstOrDefault().Name); if (shopcar.FirstOrDefault() != null) { foreach (var sc in shopcar) { await _ShopCarGoodsItemRepository.DeleteAndSaveAsyn(sc.ID); } } status = await _BoRepository.DeleteAndSaveAsyn(id); } else { if (image.IsForTitle != true) { status = await _ImageRepository.DeleteAndSaveAsyn(id); } else { status.DeleteSatus = false; status.Message = "该图片是封面,不可删除"; } } return(Json(status)); }
public async Task <IActionResult> AddDefaultShop(string id) { var status = new DeleteStatusModel(); //查询当前申请入驻用户的信息 var currUser = await _UserManager.FindByIdAsync(id); //查询当前申请入驻的用户是否已经拥有店铺 var shopForUsers = await _ShopRepository.FindByAsyn(x => x.ShopForUser.Id == currUser.Id); var shopForCurrUser = shopForUsers.FirstOrDefault(); //该判断仅仅用于调试 if (shopForCurrUser != null) { status.DeleteSatus = false; status.Message = "当前用户已经开过店铺"; return(Json(status)); } else { //根据商家申请入驻时的申请表取出部分店铺信息 var settShops = await _ShopSelltedRepository.FindByAsyn(x => x.BelongToUserID == id); var settShop = settShops.FirstOrDefault(); //用于处理店铺违规或正常使用 var shopIllegal = new SK_WM_ShopExecuteIllegal() { ModifyTime = DateTime.Now, ShopState = (SK_WM_ShopState.ShopState.已开启).ToString(), IllegalCategory = "", Description = "正常使用", }; var defaultShop = new SK_WM_Shop() { ShopForUser = currUser, BelongToUserID = currUser.Id, State = (SK_WM_ShopState.ShopState.已开启).ToString(), Name = settShop.Name, Grade = 5.0m, Collection = 0, SettledDateTime = DateTime.Now, Telephone = settShop.MobilePhone, Adress = settShop.Address, Description = "欢迎成为食刻的店主,这里是店铺描述", ShopForExecuteIllegal = shopIllegal, }; var defaultShopAvatar = new BusinessImage() { ID = Guid.NewGuid(), RelevanceObjectID = defaultShop.ID, UploadPath = "/images/logo-For-Seller.png", Description = "shopAvatar" }; var defaultShopBanner = new BusinessImage() { ID = Guid.NewGuid(), RelevanceObjectID = defaultShop.ID, UploadPath = "/images/hf.jpg", Description = "shopBanner" }; await _ShopEIllegalRepository.AddOrEditAndSaveAsyn(shopIllegal); var shop = await _ShopRepository.AddOrEditAndSaveAsyn(defaultShop); var shopIMG1 = await _ImageRepository.AddOrEditAndSaveAsyn(defaultShopAvatar); var shopIMG2 = await _ImageRepository.AddOrEditAndSaveAsyn(defaultShopBanner); if (shop) { //审核通过后修改申请表 //审核员信息 var currExamineName = User.Identity.Name; var currExamine = await _UserManager.FindByNameAsync(currExamineName); //取出当前正在审核的申请表修改状态 state为1(0待审核 1通过) 步骤为3(已经完成) var currSettled = _ShopSelltedRepository.GetAll().Where(x => x.State == 0 && x.Step == 2 && x.BelongToUserID == currUser.Id).FirstOrDefault(); /* var currSettled = currSettleds.FirstOrDefault()*/ ; currSettled.State = 1; currSettled.Step = 3; currSettled.BelongToExamineID = currExamine.Id; currSettled.ShopForExamine = currExamine; var sett = await _ShopSelltedRepository.AddOrEditAndSaveAsyn(currSettled); //返回审核操作成功的信息 status.DeleteSatus = true; status.Message = "审核通过操作成功,已经为用户添加一个默认店铺!"; } return(Json(status)); } }