/// <summary> /// 删除商铺收藏 /// </summary> /// <param name="user">登陆用户基本信息</param> /// <param name="shopsFavorite">商铺收藏实体</param> /// <param name="cancellationToken">验证</param> /// <returns></returns> public async Task DeleteAsync(SimpleUser user, ShopsFavorite shopsFavorite, CancellationToken cancellationToken = default(CancellationToken)) { if (user == null) { throw new ArgumentNullException(nameof(user)); } if (shopsFavorite == null) { throw new ArgumentNullException(nameof(shopsFavorite)); } //删除基本信息 shopsFavorite.DeleteTime = DateTime.Now; shopsFavorite.DeleteUser = user.Id; shopsFavorite.IsDeleted = true; Context.Attach(shopsFavorite); var entry = Context.Entry(shopsFavorite); entry.Property(x => x.IsDeleted).IsModified = true; entry.Property(x => x.DeleteUser).IsModified = true; entry.Property(x => x.DeleteTime).IsModified = true; try { await Context.SaveChangesAsync(cancellationToken); } catch (DbUpdateConcurrencyException) { throw; } }
/// <summary> /// 新增商铺收藏信息 /// </summary> /// <param name="shopsFavorite">实体</param> /// <param name="cancellationToken">验证</param> /// <returns></returns> public async Task <ShopsFavorite> CreateAsync(ShopsFavorite shopsFavorite, CancellationToken cancellationToken = default(CancellationToken)) { if (shopsFavorite == null) { throw new ArgumentNullException(nameof(shopsFavorite)); } Context.Add(shopsFavorite); await Context.SaveChangesAsync(cancellationToken); return(shopsFavorite); }
/// <summary> /// 修改商铺收藏信息 /// </summary> /// <param name="shopsFavorite"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task UpdateAsync(ShopsFavorite shopsFavorite, CancellationToken cancellationToken = default(CancellationToken)) { if (shopsFavorite == null) { throw new ArgumentNullException(nameof(shopsFavorite)); } Context.Attach(shopsFavorite); Context.Update(shopsFavorite); try { await Context.SaveChangesAsync(cancellationToken); } catch (DbUpdateConcurrencyException) { } }