Ejemplo n.º 1
0
        /// <summary>
        /// 删除带看
        /// </summary>
        /// <param name="user">登陆用户基本信息</param>
        /// <param name="beltLook">带看实体</param>
        /// <param name="cancellationToken">验证</param>
        /// <returns></returns>
        public async Task DeleteAsync(SimpleUser user, BeltLook beltLook, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }

            if (beltLook == null)
            {
                throw new ArgumentNullException(nameof(beltLook));
            }
            //删除基本信息
            beltLook.DeleteTime = DateTime.Now;
            beltLook.DeleteUser = user.Id;
            beltLook.IsDeleted  = true;
            Context.Attach(beltLook);
            var entry = Context.Entry(beltLook);

            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;
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 修改带看信息
 /// </summary>
 /// <param name="beltLook"></param>
 /// <param name="cancellationToken"></param>
 /// <returns></returns>
 public async Task UpdateAsync(BeltLook beltLook, CancellationToken cancellationToken = default(CancellationToken))
 {
     if (beltLook == null)
     {
         throw new ArgumentNullException(nameof(beltLook));
     }
     Context.Attach(beltLook);
     Context.Update(beltLook);
     try
     {
         await Context.SaveChangesAsync(cancellationToken);
     }
     catch (DbUpdateConcurrencyException) { }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 新增带看信息
        /// </summary>
        /// <param name="beltLook">实体</param>
        /// <param name="cancellationToken">验证</param>
        /// <returns></returns>
        public async Task <BeltLook> CreateAsync(BeltLook beltLook, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (beltLook == null)
            {
                throw new ArgumentNullException(nameof(beltLook));
            }
            Context.Add(beltLook);

            //增加用户带看次数
            var customerinfo = await Context.CustomerInfos.FindAsync(beltLook.CustomerId);

            customerinfo.BeltNum = customerinfo.BeltNum + 1;
            Context.Attach(customerinfo);
            Context.Update(customerinfo);

            await Context.SaveChangesAsync(cancellationToken);

            return(beltLook);
        }