Exemple #1
0
        public void AuditBrand(long id, ShopBrandApplysInfo.BrandAuditStatus status)
        {
            ShopBrandsInfo      shopBrandsInfo;
            ShopBrandApplysInfo nullable = this.context.ShopBrandApplysInfo.FindById <ShopBrandApplysInfo>(id);

            nullable.AuditStatus = (int)status;
            if (status == ShopBrandApplysInfo.BrandAuditStatus.Audited)
            {
                if (nullable.ApplyMode != 2)
                {
                    shopBrandsInfo = new ShopBrandsInfo()
                    {
                        BrandId = nullable.BrandId.Value,
                        ShopId  = nullable.ShopId
                    };
                    this.context.ShopBrandsInfo.Add(shopBrandsInfo);
                    this.context.SaveChanges();
                }
                else
                {
                    BrandInfo brandInfo = (
                        from r in this.context.BrandInfo
                        where r.Name.ToLower() == nullable.BrandName.ToLower()
                        select r).FirstOrDefault <BrandInfo>();
                    if (brandInfo != null)
                    {
                        shopBrandsInfo = new ShopBrandsInfo()
                        {
                            BrandId = brandInfo.Id,
                            ShopId  = nullable.ShopId
                        };
                        this.context.ShopBrandsInfo.Add(shopBrandsInfo);
                        this.context.SaveChanges();
                    }
                    else
                    {
                        BrandInfo brandInfo1 = new BrandInfo()
                        {
                            Name        = nullable.BrandName.Trim(),
                            Logo        = nullable.Logo,
                            Description = nullable.Description
                        };
                        BrandInfo brandInfo2 = brandInfo1;
                        this.context.BrandInfo.Add(brandInfo2);
                        this.context.SaveChanges();
                        nullable.BrandId = new long?(brandInfo2.Id);
                        BrandInfo brand = this.GetBrand(brandInfo2.Id);
                        brand.Logo     = this.MoveImages(brand.Id, brand.Logo, 1);
                        shopBrandsInfo = new ShopBrandsInfo()
                        {
                            BrandId = brand.Id,
                            ShopId  = nullable.ShopId
                        };
                        this.context.ShopBrandsInfo.Add(shopBrandsInfo);
                        this.context.SaveChanges();
                    }
                }
            }
            this.context.SaveChanges();
        }
        public void AuditBrand(long id, Himall.Model.ShopBrandApplysInfo.BrandAuditStatus status)
        {
            var m = Context.ShopBrandApplysInfo.FindById(id);

            m.AuditStatus = (int)status;
            if (status == Himall.Model.ShopBrandApplysInfo.BrandAuditStatus.Audited)             //审核通过
            {
                if (m.ApplyMode == (int)Himall.Model.ShopBrandApplysInfo.BrandApplyMode.New)     //申请的是新品牌
                {
                    var model = Context.BrandInfo.Where(r => r.Name.ToLower() == m.BrandName.ToLower() && r.IsDeleted == false).FirstOrDefault();
                    if (model == null)                     //是否已存在该品牌
                    {
                        //向品牌表里加入一条数据
                        BrandInfo brand = new BrandInfo()
                        {
                            Name        = m.BrandName.Trim(),
                            Logo        = m.Logo,
                            Description = m.Description
                        };

                        Context.BrandInfo.Add(brand);
                        Context.SaveChanges();

                        //关联申请表与品牌表的联系
                        m.BrandId = brand.Id;

                        BrandInfo b = GetBrand(brand.Id);
                        b.Logo = MoveImages(b.Id, b.Logo, 1);

                        //向诊所品牌表加入一条数据
                        ShopBrandsInfo info = new ShopBrandsInfo();
                        info.BrandId = b.Id;
                        info.ShopId  = m.ShopId;

                        Context.ShopBrandsInfo.Add(info);
                        Context.SaveChanges();
                    }
                    else
                    {
                        //向诊所品牌表加入一条数据
                        ShopBrandsInfo info = new ShopBrandsInfo();
                        info.BrandId = model.Id;
                        info.ShopId  = m.ShopId;

                        Context.ShopBrandsInfo.Add(info);
                        Context.SaveChanges();
                    }
                }
                else
                {
                    //向诊所品牌表加入一条数据
                    ShopBrandsInfo info = new ShopBrandsInfo();
                    info.BrandId = (long)m.BrandId;
                    info.ShopId  = m.ShopId;

                    Context.ShopBrandsInfo.Add(info);
                    Context.SaveChanges();
                }
            }
            Context.SaveChanges();
        }