Exemplo n.º 1
0
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="list"></param>
        /// <returns></returns>
        public int Update(CustomerEntity entity, List <CusAddressEntity> list)
        {
            entity.IncludeCusName(true)
            .IncludeEmail(true)
            .IncludeFax(true)
            .IncludePhone(true)
            .IncludeRemark(true)
            .IncludeCusType(true)
            ;
            entity.Where(a => a.CusNum == entity.CusNum);
            int line = this.Customer.Update(entity);

            if (!list.IsNullOrEmpty())
            {
                foreach (CusAddressEntity item in list)
                {
                    item.CusNum = entity.CusNum;
                    CusAddressEntity tempEntity = new CusAddressEntity();
                    tempEntity.IncludeAll();
                    tempEntity.Where(a => a.CusNum == item.CusNum).And(a => a.SnNum == item.SnNum);
                    tempEntity = this.CusAddress.GetSingle(tempEntity);
                    if (tempEntity.IsNotNull())
                    {
                        item.IncludeAddress(true)
                        .IncludeContact(true)
                        .IncludePhone(true)
                        ;
                        item.Where(a => a.SnNum == item.SnNum).And(a => a.CusNum == item.CusNum);
                        line += this.CusAddress.Update(item);
                    }
                    else
                    {
                        item.IncludeAll();
                        line = this.CusAddress.Add(item);
                    }
                }
                if (line > 0)
                {
                    CacheHelper.Remove(CacheKey.JOOSHOW_CUSADDRESS_CACHE);
                }
            }
            return(line);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="list"></param>
        /// <returns></returns>
        public int Update(CustomerEntity entity, List <CusAddressEntity> list)
        {
            string Key = string.Format(CacheKey.JOOSHOW_CUSADDRESS_CACHE, this.CompanyID);

            entity.IncludeCusName(true)
            .IncludeEmail(true)
            .IncludeFax(true)
            .IncludePhone(true)
            .IncludeRemark(true)
            .IncludeCusType(true)
            .IncludeCusNum(true)
            ;
            entity.Where(a => a.SnNum == entity.SnNum);
            int line = this.Customer.Update(entity);

            if (!list.IsNullOrEmpty())
            {
                CusAddressEntity addSource = new CusAddressEntity();
                addSource.IncludeAll();
                addSource.Where(a => a.CustomerSN == entity.SnNum)
                .And(a => a.IsDelete == (int)EIsDelete.NotDelete)
                ;
                List <CusAddressEntity> listSource = this.CusAddress.GetList(addSource);
                listSource = listSource.IsNull() ? new List <CusAddressEntity>() : listSource;

                //处理未删除的
                foreach (CusAddressEntity item in list.Where(a => a.IsDelete == (int)EIsDelete.NotDelete))
                {
                    if (listSource.Exists(a => a.SnNum == item.SnNum))
                    {
                        item.Include(a => new { a.Contact, a.Phone, a.Address, a.Remark });
                        item.Where(a => a.SnNum == item.SnNum);
                        line += this.CusAddress.Update(item);
                    }
                    else
                    {
                        item.IncludeAll();
                        item.CustomerSN = entity.SnNum;
                        item.CreateTime = DateTime.Now;
                        item.IsDelete   = (int)EIsDelete.NotDelete;
                        item.CompanyID  = this.CompanyID;
                        line           += this.CusAddress.Add(item);
                    }
                }

                //处理删除的
                foreach (CusAddressEntity item in listSource)
                {
                    if (!list.Exists(a => a.SnNum == item.SnNum))
                    {
                        item.IsDelete = (int)EIsDelete.Deleted;
                        item.IncludeIsDelete(true);
                        item.Where(a => a.SnNum == item.SnNum);
                        line += this.CusAddress.Update(item);
                    }
                }
            }
            if (line > 0)
            {
                CacheHelper.Remove(Key);
            }
            return(line);
        }