Example #1
0
        public static UserIntegrals Get(string id)
        {
            UserIntegrals integral = null;

            if (!General.IsNullable(id))
            {
                using (WMContext context = new WMContext())
                {
                    integral = (
                        from ui in context.UserIntegrals
                        join s in context.Options on ui.SourceId equals s.Id
                        where ui.Id.Equals(id)
                        select new WMUserIntegrals
                    {
                        Id = ui.Id,
                        SourceId = ui.SourceId,
                        SourceName = s.Name,
                        UserId = ui.UserId,
                        Integral = ui.Integral,
                        AddDate = ui.AddDate
                    }
                        ).FirstOrDefault();
                }
            }

            return(integral);
        }
Example #2
0
        public static List<WMOrderExpress> GetList(out int pageCount, string name = null, int pageIndex = 0, int pageSize = 0)
        {
            List<WMOrderExpress> list = null;
            bool isName = !General.IsNullable(name);
            pageCount = 0;

            using (WMContext context = new WMContext())
            {
                var query = (
                    from oe in context.OrderExpress
                    where (isName ? oe.Name.Contains(name) : true)
                    orderby oe.AddDate descending
                    select new WMOrderExpress
                    {
                        Id = oe.Id,
                        Name = oe.Name,
                        URL = oe.URL,
                        AddDate = oe.AddDate
                    }
                );

                if (query != null)
                {
                    pageCount = query.Count();

                    if (pageIndex >= 0 && pageSize > 0)
                        query = query.Skip(pageIndex * pageSize).Take(pageSize);

                    list = query.ToList();
                }
            }

            return list;
        }
Example #3
0
        public static WMGoodImages Get(string id)
        {
            WMGoodImages image = null;

            if (!General.IsNullable(id))
            {
                using (WMContext context = new WMContext())
                {
                    image = (
                        from gi in context.GoodImages
                        where gi.Id.Equals(id)
                        select new WMGoodImages
                        {
                            Id = gi.Id,
                            GoodId = gi.GoodId,
                            URL = gi.URL,
                            IsCover = gi.IsCover,
                            AddDate = gi.AddDate
                        }
                    ).FirstOrDefault();
                }
            }

            return image;
        }
Example #4
0
        public bool Delete(string id)
        {
            if (!General.IsNullable(id))
            {
                using (WMContext context = new WMContext())
                {
                    var list = (
                        from gc in context.GoodCategories
                        where gc.Id.Equals(id) ||
                        gc.ParentId.Equals(id)
                        select gc
                        );

                    if (list != null)
                    {
                        foreach (var model in list)
                        {
                            context.GoodCategories.Remove(model);
                        }

                        context.SaveChanges();
                        return(true);
                    }
                }
            }

            return(false);
        }
Example #5
0
        /// <summary>
        /// 用购物车的数据填充订单商品表
        /// </summary>
        /// <param name="orderId">订单ID</param>
        /// <param name="shopCars">购物车数据</param>
        /// <returns>添加成功返回TRUE,否则返回FALSE</returns>
        public static bool AddList(string orderId, List<WMShopCars> shopCars)
        {
            if (!General.IsNullable(orderId) && !General.IsNullable(shopCars))
            {
                WMOrderGoods model = null;
                using (WMContext context = new WMContext())
                {
                    foreach (WMShopCars item in shopCars)
                    {
                        model = new WMOrderGoods {
                            Id = General.UniqueString(),
                            OrderId = orderId,
                            GoodId = item.GoodId,
                            Price = item.Price,
                            Count = item.Count
                        };

                        context.OrderGoods.Add(model);
                    }

                    context.SaveChanges();
                }

                return true;
            }

            return false;
        }
Example #6
0
        public bool Add()
        {
            if (this.Valid())
            {
                this.Id      = General.UniqueString(this.Id);
                this.AddDate = DateTime.Now;

                using (WMContext context = new WMContext())
                {
                    UserIntegrals model = new UserIntegrals
                    {
                        Id       = this.Id,
                        SourceId = this.SourceId,
                        UserId   = this.UserId,
                        Integral = this.Integral,
                        AddDate  = this.AddDate
                    };

                    context.UserIntegrals.Add(model);
                    context.SaveChanges();
                }

                return(WMUsers.UpdateIntegral(this.UserId, this.Integral));
            }

            return(false);
        }
Example #7
0
        public static bool Clear(string userId)
        {
            if (!General.IsNullable(userId))
            {
                using (WMContext context = new WMContext())
                {
                    var list = (
                        from car in context.ShopCars
                        where car.UserId.Equals(userId)
                        select car
                    );

                    if (list != null)
                    {
                        foreach (var item in list)
                            context.ShopCars.Remove(item);

                        context.SaveChanges();
                        return true;
                    }
                }
            }

            return false;
        }
Example #8
0
        public static WMAdministrators Get(int adminId)
        {
            WMAdministrators admin = null;

            if (adminId > 0)
            {
                using (WMContext context = new WMContext())
                {
                    admin = (
                        from ad in context.Administartors
                        join r in context.Options on ad.RoleId equals r.Id
                        join s in context.Options on ad.StatusId equals s.Id
                        where ad.Id == adminId
                        select new WMAdministrators
                        {
                            Id = ad.Id,
                            RoleId = ad.RoleId,
                            RoleName = r.Name,
                            UserName = ad.UserName,
                            Password = ad.Password,
                            StatusId = ad.StatusId,
                            StatusName = s.Name,
                            AddDate = ad.AddDate
                        }
                    ).FirstOrDefault();
                }
            }

            return admin;
        }
Example #9
0
        public static bool UpdateStatus(string id, int stateId)
        {
            if (!General.IsNullable(id) && stateId > 0)
            {
                using (WMContext context = new WMContext())
                {
                    Goods model = context.Goods.Find(id);

                    if (model != null)
                    {
                        model.StatusId = stateId;

                        //恢复上架的商品,上架时间从恢复之时算起
                        if (stateId == 503)
                        {
                            model.AddDate = DateTime.Now;
                        }

                        context.SaveChanges();
                        return(true);
                    }
                }
            }

            return(false);
        }
Example #10
0
        public static List <WMGoodImages> GetList(string goodId)
        {
            List <WMGoodImages> list = null;

            if (!General.IsNullable(goodId))
            {
                using (WMContext context = new WMContext())
                {
                    list = (
                        from gi in context.GoodImages
                        where gi.GoodId.Equals(goodId)
                        orderby gi.IsCover descending, gi.AddDate descending
                        select new WMGoodImages
                    {
                        Id = gi.Id,
                        GoodId = gi.GoodId,
                        URL = gi.URL,
                        IsCover = gi.IsCover,
                        AddDate = gi.AddDate
                    }
                        ).ToList();
                }
            }

            return(list);
        }
Example #11
0
        public static WMGoodCategories Get(string id)
        {
            WMGoodCategories category = null;

            if (!General.IsNullable(id))
            {
                using (WMContext context = new WMContext())
                {
                    category = (
                        from gc in context.GoodCategories
                        where gc.Id.Equals(id)
                        select new WMGoodCategories
                    {
                        Id = gc.Id,
                        ParentId = gc.ParentId,
                        ParentName = (!gc.ParentId.Equals("root") ? context.GoodCategories.Where(g => g.Id.Equals(gc.ParentId)).Select(g => g.Name).FirstOrDefault() : "root"),
                        Name = gc.Name,
                        Level = gc.Level,
                        Sort = gc.Sort
                    }
                        ).FirstOrDefault();
                }
            }

            return(category);
        }
Example #12
0
        public static WMOrderGoods Get(string id)
        {
            WMOrderGoods model = null;

            if (!General.IsNullable(id))
            {
                using (WMContext context = new WMContext())
                {
                    model = (
                        from og in context.OrderGoods
                        join g in context.Goods on og.GoodId equals g.Id
                        where og.Id.Equals(id)
                        select new WMOrderGoods
                        {
                            Id = og.Id,
                            OrderId = og.OrderId,
                            GoodId = og.GoodId,
                            GoodName = g.Name,
                            GoodFigure = context.GoodImages.Where(gi => gi.GoodId.Equals(og.GoodId) && gi.IsCover).Select(gi => gi.URL).FirstOrDefault(),
                            GoodInteSubTotal = (g.Integral * og.Count),
                            Price = og.Price,
                            Count = og.Count
                        }
                    ).FirstOrDefault();
                }
            }

            return model;
        }
Example #13
0
        public static WMShopCars Get(string id)
        {
            WMShopCars model = null;

            if (!General.IsNullable(id))
            {
                using (WMContext context = new WMContext())
                {
                    model = (
                        from car in context.ShopCars
                        join g in context.Goods on car.GoodId equals g.Id
                        where car.Id.Equals(id)
                        select new WMShopCars
                    {
                        Id = car.Id,
                        GoodId = car.GoodId,
                        GoodName = g.Name,
                        GoodFigure = context.GoodImages.Where(gi => gi.GoodId.Equals(car.GoodId) && gi.IsCover).Select(gi => gi.URL).FirstOrDefault(),
                        UserId = car.UserId,
                        Price = car.Price,
                        Count = car.Count,
                        AddDate = car.AddDate
                    }
                        ).FirstOrDefault();
                }
            }

            return(model);
        }
Example #14
0
        public static List <WMRegions> GetList(int parentId = 0)
        {
            List <WMRegions> list = null;

            if (parentId >= 0)
            {
                using (WMContext context = new WMContext())
                {
                    list = (
                        from r in context.Regions
                        where r.ParentId == parentId
                        orderby r.Id ascending
                        select new WMRegions
                    {
                        Id = r.Id,
                        ParentId = r.ParentId,
                        Name = r.Name,
                        Level = r.Level,
                        AreaCode = r.AreaCode
                    }
                        ).ToList();
                }
            }

            return(list);
        }
Example #15
0
        /// <summary>
        /// 用购物车的数据填充订单商品表
        /// </summary>
        /// <param name="orderId">订单ID</param>
        /// <param name="shopCars">购物车数据</param>
        /// <returns>添加成功返回TRUE,否则返回FALSE</returns>
        public static bool AddList(string orderId, List <WMShopCars> shopCars)
        {
            if (!General.IsNullable(orderId) && !General.IsNullable(shopCars))
            {
                WMOrderGoods model = null;
                using (WMContext context = new WMContext())
                {
                    foreach (WMShopCars item in shopCars)
                    {
                        model = new WMOrderGoods {
                            Id      = General.UniqueString(),
                            OrderId = orderId,
                            GoodId  = item.GoodId,
                            Price   = item.Price,
                            Count   = item.Count
                        };

                        context.OrderGoods.Add(model);
                    }

                    context.SaveChanges();
                }

                return(true);
            }

            return(false);
        }
Example #16
0
        public static bool Clear(string userId)
        {
            if (!General.IsNullable(userId))
            {
                using (WMContext context = new WMContext())
                {
                    var list = (
                        from car in context.ShopCars
                        where car.UserId.Equals(userId)
                        select car
                        );

                    if (list != null)
                    {
                        foreach (var item in list)
                        {
                            context.ShopCars.Remove(item);
                        }

                        context.SaveChanges();
                        return(true);
                    }
                }
            }

            return(false);
        }
Example #17
0
        public static WMOrderGoods Get(string id)
        {
            WMOrderGoods model = null;

            if (!General.IsNullable(id))
            {
                using (WMContext context = new WMContext())
                {
                    model = (
                        from og in context.OrderGoods
                        join g in context.Goods on og.GoodId equals g.Id
                        where og.Id.Equals(id)
                        select new WMOrderGoods
                    {
                        Id = og.Id,
                        OrderId = og.OrderId,
                        GoodId = og.GoodId,
                        GoodName = g.Name,
                        GoodFigure = context.GoodImages.Where(gi => gi.GoodId.Equals(og.GoodId) && gi.IsCover).Select(gi => gi.URL).FirstOrDefault(),
                        GoodInteSubTotal = (g.Integral * og.Count),
                        Price = og.Price,
                        Count = og.Count
                    }
                        ).FirstOrDefault();
                }
            }

            return(model);
        }
Example #18
0
        public bool Add()
        {
            if (this.Valid())
            {
                this.Id = General.UniqueString(this.Id);

                using (WMContext context = new WMContext())
                {
                    OrderGoods model = new OrderGoods {
                        Id      = this.Id,
                        OrderId = this.OrderId,
                        GoodId  = this.GoodId,
                        Price   = this.Price,
                        Count   = this.Count
                    };

                    context.OrderGoods.Add(model);
                    context.SaveChanges();
                }

                return(true);
            }

            return(false);
        }
Example #19
0
        public static WMUserSets Get(string id)
        {
            WMUserSets userSet = null;

            if (!General.IsNullable(id))
            {
                DateTime now = DateTime.Now;
                using (WMContext context = new WMContext())
                {
                    userSet = (
                        from us in context.UserSets
                        join g in context.Goods on us.GoodId equals g.Id
                        join t in context.Options on us.TypeId equals t.Id
                        where us.Id.Equals(id)
                        select new WMUserSets
                        {
                            Id = us.Id,
                            TypeId = us.TypeId,
                            TypeName = t.Name,
                            UserId = us.UserId,
                            GoodId = us.GoodId,
                            GoodName = g.Name,
                            GoodFigure = context.GoodImages.Where(gi => gi.GoodId.Equals(us.GoodId) && gi.IsCover).Select(gi => gi.URL).FirstOrDefault(),
                            AddDate = us.AddDate
                        }
                    ).FirstOrDefault();
                }
            }

            return userSet;
        }
Example #20
0
        public static WMUserBonus Get(string id)
        {
            WMUserBonus model = null;

            if (!General.IsNullable(id))
            {
                using(WMContext context = new WMContext())
                {
                    model = (
                        from ub in context.UserBonus
                        where ub.Id.Equals(id)
                        select new WMUserBonus
                        {
                            Id = ub.Id,
                            UserId = ub.UserId,
                            OrderId = ub.OrderId,
                            BonusSum = ub.BonusSum,
                            AddDate = ub.AddDate
                        }
                    ).FirstOrDefault();
                }
            }

            return model;
        }
Example #21
0
        public bool Update()
        {
            if (this.Valid(true))
            {
                using (WMContext context = new WMContext())
                {
                    UserReceipts model = context.UserReceipts.Find(this.Id);

                    if (model != null)
                    {
                        model.ProvinceId = this.ProvinceId;
                        model.CityId     = this.CityId;
                        model.AreaId     = this.AreaId;
                        model.Address    = this.Address;
                        model.Contact    = this.Contact;
                        model.Phone      = this.Phone;
                        model.ZipCode    = this.ZipCode;

                        context.SaveChanges();
                        return(true);
                    }
                }
            }

            return(false);
        }
Example #22
0
        public bool Update()
        {
            if (this.Valid(true))
            {
                using (WMContext context = new WMContext())
                {
                    Goods model = context.Goods.Find(this.Id);

                    if (model != null)
                    {
                        model.CategoryId    = this.CategoryId;
                        model.BrandId       = this.BrandId;
                        model.Name          = this.Name;
                        model.OriginalPrice = this.OriginalPrice;
                        model.PresentPrice  = this.PresentPrice;
                        model.Unit          = this.Unit;
                        model.Desc          = this.Desc;
                        model.Spec          = this.Spec;
                        model.Service       = this.Service;
                        model.Integral      = this.Integral;
                        model.Clicks        = this.Clicks;
                        model.Saves         = this.Saves;
                        model.Bonus         = this.Bonus;
                        model.GoldPool      = this.GoldPool;
                        model.StatusId      = this.StatusId;

                        context.SaveChanges();
                        return(true);
                    }
                }
            }

            return(false);
        }
Example #23
0
        public static WMUserSets Get(string id)
        {
            WMUserSets userSet = null;

            if (!General.IsNullable(id))
            {
                DateTime now = DateTime.Now;
                using (WMContext context = new WMContext())
                {
                    userSet = (
                        from us in context.UserSets
                        join g in context.Goods on us.GoodId equals g.Id
                        join t in context.Options on us.TypeId equals t.Id
                        where us.Id.Equals(id)
                        select new WMUserSets
                    {
                        Id = us.Id,
                        TypeId = us.TypeId,
                        TypeName = t.Name,
                        UserId = us.UserId,
                        GoodId = us.GoodId,
                        GoodName = g.Name,
                        GoodFigure = context.GoodImages.Where(gi => gi.GoodId.Equals(us.GoodId) && gi.IsCover).Select(gi => gi.URL).FirstOrDefault(),
                        AddDate = us.AddDate
                    }
                        ).FirstOrDefault();
                }
            }

            return(userSet);
        }
Example #24
0
        public static WMUserBonus Get(string id)
        {
            WMUserBonus model = null;

            if (!General.IsNullable(id))
            {
                using (WMContext context = new WMContext())
                {
                    model = (
                        from ub in context.UserBonus
                        where ub.Id.Equals(id)
                        select new WMUserBonus
                    {
                        Id = ub.Id,
                        UserId = ub.UserId,
                        OrderId = ub.OrderId,
                        BonusSum = ub.BonusSum,
                        AddDate = ub.AddDate
                    }
                        ).FirstOrDefault();
                }
            }

            return(model);
        }
Example #25
0
        public static bool Delete(string id)
        {
            if (!General.IsNullable(id))
            {
                string fileName = null;

                using (WMContext context = new WMContext())
                {
                    GoodBrands model = context.GoodBrands.Find(id);

                    if (model != null)
                    {
                        if (!General.IsNullable(model.Logo))
                        {
                            fileName = "~" + model.Logo;
                        }

                        context.GoodBrands.Remove(model);
                        context.SaveChanges();
                    }
                }

                if (!General.IsNullable(fileName))
                {
                    return(Jumpcity.IO.FileHelper.DeleteFile(fileName));
                }

                return(true);
            }

            return(false);
        }
Example #26
0
        public static WMAdministrators Get(int adminId)
        {
            WMAdministrators admin = null;

            if (adminId > 0)
            {
                using (WMContext context = new WMContext())
                {
                    admin = (
                        from ad in context.Administartors
                        join r in context.Options on ad.RoleId equals r.Id
                        join s in context.Options on ad.StatusId equals s.Id
                        where ad.Id == adminId
                        select new WMAdministrators
                    {
                        Id = ad.Id,
                        RoleId = ad.RoleId,
                        RoleName = r.Name,
                        UserName = ad.UserName,
                        Password = ad.Password,
                        StatusId = ad.StatusId,
                        StatusName = s.Name,
                        AddDate = ad.AddDate
                    }
                        ).FirstOrDefault();
                }
            }

            return(admin);
        }
Example #27
0
        public bool Add()
        {
            if (this.Valid())
            {
                this.AddDate = DateTime.Now;

                using (WMContext context = new WMContext())
                {
                    Administartors model = new Administartors {
                        RoleId   = this.RoleId,
                        UserName = this.UserName,
                        Password = this.Password,
                        StatusId = this.StatusId,
                        AddDate  = this.AddDate
                    };

                    context.Administartors.Add(model);
                    context.SaveChanges();
                }

                return(true);
            }

            return(false);
        }
Example #28
0
        public bool Update(bool updatePwd = false)
        {
            if (this.Valid(true))
            {
                using (WMContext context = new WMContext())
                {
                    Users model = context.Users.Find(this.Id);

                    if (model != null)
                    {
                        model.UserName = this.UserName;
                        model.RoleId   = this.RoleId;
                        model.NickName = this.NickName;
                        model.Integral = this.Integral;
                        model.Image    = this.Image;
                        model.Mobile   = this.Mobile;
                        model.BankCard = this.BankCard;
                        model.StatusId = this.StatusId;
                        if (updatePwd)
                        {
                            model.Password = this.Password;
                        }

                        context.SaveChanges();
                        return(true);
                    }
                }
            }

            return(false);
        }
Example #29
0
        public static WMAdministrators Login(string userName, string pwd)
        {
            WMAdministrators admin = null;

            if (!General.IsNullable(userName) && !General.IsNullable(pwd))
            {
                int adminId = 0;

                using (WMContext context = new WMContext())
                {
                    adminId = (
                        from ad in context.Administartors
                        where ad.StatusId == 201 &&
                        ad.Password.Equals(pwd) &&
                        ad.UserName.Equals(userName)
                        select ad.Id
                        ).FirstOrDefault();
                }

                if (adminId > 0)
                {
                    admin = Get(adminId);
                }
            }

            return(admin);
        }
Example #30
0
        public static bool Delete(string id)
        {
            if (!General.IsNullable(id))
            {
                string fileName = null;

                using (WMContext context = new WMContext())
                {
                    GoodBrands model = context.GoodBrands.Find(id);

                    if (model != null)
                    {
                        if (!General.IsNullable(model.Logo))
                            fileName = "~" + model.Logo;

                        context.GoodBrands.Remove(model);
                        context.SaveChanges();
                    }
                }

                if (!General.IsNullable(fileName))
                    return Jumpcity.IO.FileHelper.DeleteFile(fileName);

                return true;
            }

            return false;
        }
Example #31
0
        public bool Add()
        {
            if (this.Valid())
            {
                this.Id      = General.UniqueString(this.Id);
                this.AddDate = DateTime.Now;

                using (WMContext context = new WMContext())
                {
                    Users model = new Users {
                        Id       = this.Id,
                        RoleId   = this.RoleId,
                        OpenId   = this.OpenId,
                        UserName = this.UserName,
                        Password = this.Password,
                        NickName = this.NickName,
                        Image    = this.Image,
                        Mobile   = this.Mobile,
                        BankCard = this.BankCard,
                        StatusId = this.StatusId,
                        AddDate  = this.AddDate
                    };

                    context.Users.Add(model);
                    context.SaveChanges();
                }

                return(true);
            }

            return(false);
        }
Example #32
0
        public static bool UpdateCover(string id)
        {
            if (!General.IsNullable(id))
            {
                using (WMContext context = new WMContext())
                {
                    GoodImages model = context.GoodImages.Find(id);

                    if (model != null)
                    {
                        GoodImages old = context.GoodImages.Where(gi => gi.GoodId.Equals(model.GoodId) && gi.IsCover).FirstOrDefault();
                        if (old != null)
                        {
                            old.IsCover = false;
                        }
                        model.IsCover = true;

                        context.SaveChanges();
                        return(true);
                    }
                }
            }

            return(false);
        }
Example #33
0
        public static WMUsers Login(string userKey, string pwd)
        {
            WMUsers user = null;

            if (!General.IsNullable(userKey) && !General.IsNullable(pwd))
            {
                string userId = null;

                using (WMContext context = new WMContext())
                {
                    userId = (
                        from u in context.Users
                        where u.StatusId == 201 &&
                        u.Password.Equals(pwd) &&
                        (u.UserName.Equals(userKey) || u.Mobile == userKey)
                        select u.Id
                        ).FirstOrDefault();
                }

                if (userId != null)
                {
                    user = Get(userId);
                }
            }

            return(user);
        }
Example #34
0
        public bool Add()
        {
            if (this.Valid())
            {
                this.Id      = General.UniqueString(this.Id);
                this.AddDate = DateTime.Now;

                using (WMContext context = new WMContext())
                {
                    this.IsCover = (context.GoodImages.Where(gi => gi.GoodId.Equals(this.GoodId)).Count() == 0);

                    GoodImages model = new GoodImages {
                        Id      = this.Id,
                        GoodId  = this.GoodId,
                        URL     = this.URL,
                        IsCover = this.IsCover,
                        AddDate = this.AddDate
                    };

                    context.GoodImages.Add(model);
                    context.SaveChanges();
                }

                return(true);
            }

            return(false);
        }
Example #35
0
        public static UserIntegrals Get(string id)
        {
            UserIntegrals integral = null;

            if (!General.IsNullable(id))
            {
                using (WMContext context = new WMContext())
                {
                    integral = (
                        from ui in context.UserIntegrals
                        join s in context.Options on ui.SourceId equals s.Id
                        where ui.Id.Equals(id)
                        select new WMUserIntegrals
                        {
                            Id = ui.Id,
                            SourceId = ui.SourceId,
                            SourceName = s.Name,
                            UserId = ui.UserId,
                            Integral = ui.Integral,
                            AddDate = ui.AddDate
                        }
                    ).FirstOrDefault();
                }
            }

            return integral;
        }
Example #36
0
        public static WMGoodImages Get(string id)
        {
            WMGoodImages image = null;

            if (!General.IsNullable(id))
            {
                using (WMContext context = new WMContext())
                {
                    image = (
                        from gi in context.GoodImages
                        where gi.Id.Equals(id)
                        select new WMGoodImages
                    {
                        Id = gi.Id,
                        GoodId = gi.GoodId,
                        URL = gi.URL,
                        IsCover = gi.IsCover,
                        AddDate = gi.AddDate
                    }
                        ).FirstOrDefault();
                }
            }

            return(image);
        }
Example #37
0
        public bool Add()
        {
            if (this.Valid())
            {
                this.Id      = General.UniqueString(this.Id);
                this.AddDate = DateTime.Now;

                using (WMContext context = new WMContext())
                {
                    UserReceipts model = new UserReceipts {
                        Id         = this.Id,
                        UserId     = this.UserId,
                        ProvinceId = this.ProvinceId,
                        CityId     = this.CityId,
                        AreaId     = this.AreaId,
                        Address    = this.Address,
                        Contact    = this.Contact,
                        Phone      = this.Phone,
                        ZipCode    = this.ZipCode,
                        AddDate    = this.AddDate
                    };

                    context.UserReceipts.Add(model);
                    context.SaveChanges();
                }

                return(true);
            }

            return(false);
        }
Example #38
0
        /// <summary>
        /// 为指定的订单付款,并将相应的购买积分添加到用户的账户中
        /// </summary>
        /// <param name="orderId">要付款的订单ID</param>
        /// <returns>付款成功返回TRUE,否则返回FALSE</returns>
        public static bool Payment(string orderId)
        {
            bool flag = false;

            if (!General.IsNullable(orderId))
            {
                string userId = null;

                using (WMContext context = new WMContext())
                {
                    Orders model = context.Orders.Find(orderId);

                    if (model != null)
                    {
                        userId     = model.UserId;
                        model.Paid = true;
                        context.SaveChanges();
                        flag = true;
                    }
                }

                if (flag && !General.IsNullable(userId))
                {
                    int inteSum = WMOrderGoods.GetIntegralSum(orderId);
                    return(new WMUserIntegrals {
                        UserId = userId,
                        Integral = inteSum
                    }.Add());
                }
            }

            return(flag);
        }
Example #39
0
        public bool Add()
        {
            if (this.Valid())
            {
                this.Id      = General.UniqueString(this.Id);
                this.AddDate = DateTime.Now;

                using (WMContext context = new WMContext())
                {
                    UserBonus model = new UserBonus {
                        Id       = this.Id,
                        UserId   = this.UserId,
                        OrderId  = this.OrderId,
                        BonusSum = this.BonusSum,
                        AddDate  = this.AddDate
                    };

                    context.UserBonus.Add(model);
                    context.SaveChanges();
                }

                return(true);
            }

            return(false);
        }
Example #40
0
        public static WMUsers Login(string openId)
        {
            WMUsers user = null;

            if (!General.IsNullable(openId))
            {
                string userId = null;

                using (WMContext context = new WMContext())
                {
                    userId = (
                        from u in context.Users
                        where u.StatusId == 201 &&
                        u.OpenId == openId
                        select u.Id
                        ).FirstOrDefault();
                }

                if (userId != null)
                {
                    user = Get(userId);
                }
            }

            return(user);
        }
Example #41
0
        public static List<WMGoodBrands> GetList(out int pageCount, string name = null, int pageIndex = 0, int pageSize = 0)
        {
            List<WMGoodBrands> list = null;
            bool isName = !General.IsNullable(name);
            pageCount = 0;

            using (WMContext context = new WMContext())
            {
                var query = (
                    from gb in context.GoodBrands
                    where (isName ? gb.Name.Contains(name) : true)
                    orderby gb.Logo descending
                    select new WMGoodBrands
                    {
                        Id = gb.Id,
                        Name = gb.Name,
                        Logo = gb.Logo,
                        URL = gb.URL
                    }
                );

                if (query != null)
                {
                    pageCount = query.Count();

                    if (pageIndex >= 0 && pageSize > 0)
                        query = query.Skip(pageIndex * pageSize).Take(pageSize);

                    list = query.ToList();
                }
            }

            return list;
        }
Example #42
0
        public static bool Delete(int adminId)
        {
            if (adminId > 0)
            {
                using (WMContext context = new WMContext())
                {
                    Administartors model = context.Administartors.Find(adminId);

                    if (model != null)
                    {
                        model.StatusId = 203;
                        context.SaveChanges();
                        return true;
                    }
                }
            }

            return false;
        }
Example #43
0
        public static List<WMGoodState> GetList()
        {
            List<WMGoodState> list = null;

            using (WMContext context = new WMContext())
            {
                list = (
                    from r in context.Options
                    where r.Group.Equals(groupName)
                    select new WMGoodState
                    {
                        StateId = r.Id,
                        StateName = r.Name
                    }
                ).ToList();
            }

            return list;
        }
Example #44
0
        public static List<WMOrderPay> GetList()
        {
            List<WMOrderPay> list = null;

            using (WMContext context = new WMContext())
            {
                list = (
                    from r in context.Options
                    where r.Group.Equals(groupName)
                    select new WMOrderPay
                    {
                        PayId = r.Id,
                        PayName = r.Name
                    }
                ).ToList();
            }

            return list;
        }
Example #45
0
        public static bool Delete(string userId)
        {
            if (!General.IsNullable(userId))
            {
                using (WMContext context = new WMContext())
                {
                    Users model = context.Users.Find(userId);

                    if (model != null)
                    {
                        model.StatusId = 203;
                        context.SaveChanges();
                        return true;
                    }
                }
            }

            return false;
        }
Example #46
0
        public static bool Delete(string id)
        {
            if (!General.IsNullable(id))
            {
                using (WMContext context = new WMContext())
                {
                    UserSets model = context.UserSets.Find(id);

                    if (model != null)
                    {
                        context.UserSets.Remove(model);
                        context.SaveChanges();
                        return true;
                    }
                }
            }

            return false;
        }
Example #47
0
        public static List<WMUserClicks> GetList(out int pageCount, string promoterId = null, int pageIndex = 0, int pageSize = 0)
        {
            List<WMUserClicks> list = null;
            bool flag = !General.IsNullable(promoterId);
            pageCount = 0;

            using (WMContext context = new WMContext())
            {
                var query = (
                    from uc in context.UserClicks
                    join p in context.Users on uc.PromoterId equals p.Id
                    join c in context.Users on uc.CustomerId equals c.Id
                    join g in context.Goods on uc.GoodId equals g.Id
                    where (flag ? uc.PromoterId.Equals(promoterId) : true)
                    orderby uc.AddDate descending
                    select new WMUserClicks
                    {
                        Id = uc.Id,
                        PromoterId = uc.PromoterId,
                        PromoterName = p.NickName,
                        CustomerId = uc.CustomerId,
                        CustomerName = c.NickName,
                        GoodId = uc.GoodId,
                        GoodName = g.Name,
                        GoodFigure = context.GoodImages.Where(gi => gi.GoodId.Equals(uc.GoodId) && gi.IsCover).Select(gi => gi.URL).FirstOrDefault(),
                        AddDate = uc.AddDate
                    }
                );

                if (query != null)
                {
                    pageCount = query.Count();

                    if (pageIndex >= 0 && pageSize > 0)
                        query = query.Skip(pageIndex * pageSize).Take(pageSize);

                    list = query.ToList();
                }
            }

            return list;
        }
Example #48
0
        public static List<WMOrderState> GetList()
        {
            List<WMOrderState> list = null;

            using (WMContext context = new WMContext())
            {
                list = (
                    from r in context.Options
                    where r.Group.Equals(groupName)
                    select new WMOrderState
                    {
                        StateId = r.Id,
                        StateName = r.Name,
                        StateCount = context.Orders.Count(o => o.StatusId == r.Id)
                    }
                ).ToList();
            }

            return list;
        }
Example #49
0
        public static List<WMAdministrators> GetList(out int pageCount, int roleId = 0, int stateId = 0, int pageIndex = 0, int pageSize = 0)
        {
            List<WMAdministrators> list = null;
            pageCount = 0;

            using (WMContext context = new WMContext())
            {
                var query = (
                    from ad in context.Administartors
                    join r in context.Options on ad.RoleId equals r.Id
                    join s in context.Options on ad.StatusId equals s.Id
                    where ad.StatusId != 203
                       && (roleId > 0 ? ad.RoleId == roleId : true)
                       && (stateId > 0 ? ad.StatusId == stateId : true)
                    orderby ad.StatusId ascending, ad.AddDate descending
                    select new WMAdministrators
                    {
                        Id = ad.Id,
                        RoleId = ad.RoleId,
                        RoleName = r.Name,
                        UserName = ad.UserName,
                        Password = ad.Password,
                        StatusId = ad.StatusId,
                        StatusName = s.Name,
                        AddDate = ad.AddDate
                    }
                );

                if (query != null)
                {
                    pageCount = query.Count();

                    if (pageIndex >= 0 && pageSize > 0)
                        query = query.Skip(pageIndex * pageSize).Take(pageSize);

                    list = query.ToList();
                }
            }

            return list;
        }
Example #50
0
        public static int GetClickCount(string promoterId, string goodId = null)
        {
            int count = 0;

            if (!General.IsNullable(promoterId))
            {
                bool isGood = !General.IsNullable(goodId);

                using (WMContext context = new WMContext())
                {
                    count = (
                        from uc in context.UserClicks
                        where uc.PromoterId.Equals(promoterId)
                           && (isGood ? uc.GoodId.Equals(goodId) : true)
                        select uc.Id
                    ).Count();
                }
            }

            return count;
        }
Example #51
0
        public static WMOrderState Get(int stateId)
        {
            WMOrderState state = null;

            using (WMContext context = new WMContext())
            {
                state = (
                    from r in context.Options
                    where r.Group.Equals(groupName)
                       && r.Id == stateId
                    select new WMOrderState
                    {
                        StateId = r.Id,
                        StateName = r.Name,
                        StateCount = context.Orders.Count(o => o.StatusId == r.Id)
                    }
                ).FirstOrDefault();
            }

            return state;
        }
Example #52
0
        public static WMUsers Get(string userId)
        {
            WMUsers user = null;

            if (!General.IsNullable(userId))
            {
                using (WMContext context = new WMContext())
                {
                    user = (
                        from u in context.Users
                        join r in context.Options on u.RoleId equals r.Id
                        join s in context.Options on u.StatusId equals s.Id
                        where u.Id.Equals(userId)
                        select new WMUsers
                        {
                            Id = u.Id,
                            RoleId = u.RoleId,
                            RoleName = r.Name,
                            OpenId = u.OpenId,
                            UnionId = u.UnionId,
                            UserName = u.UserName,
                            Password = u.Password,
                            NickName = u.NickName,
                            Integral = u.Integral,
                            Image = u.Image,
                            Mobile = u.Mobile,
                            Identity = u.Identity,
                            BankAccount = u.BankAccount,
                            BankCard = u.BankCard,
                            BankName = u.BankName,
                            StatusId = u.StatusId,
                            StatusName = s.Name,
                            AddDate = u.AddDate
                        }
                    ).FirstOrDefault();
                }
            }

            return user;
        }
Example #53
0
        public static bool Delete(string id)
        {
            if (!General.IsNullable(id))
            {
                string fileName = null;

                using (WMContext context =new WMContext())
                {
                    GoodImages model = context.GoodImages.Find(id);

                    if (model != null)
                    {
                        fileName = "~" + model.URL;
                        GoodImages newCover = null;

                        if (model.IsCover)
                        {
                            newCover = (
                                from gi in context.GoodImages
                                where gi.GoodId.Equals(model.GoodId)
                                   && gi.Id != model.Id
                                orderby gi.AddDate descending
                                select gi
                            ).FirstOrDefault();

                            if (newCover != null)
                                newCover.IsCover = true;
                        }

                        context.GoodImages.Remove(model);
                        context.SaveChanges();
                    }
                }

                return FileHelper.DeleteFile(fileName);
            }

            return false;
        }
Example #54
0
        public static List<WMUserBonus> GetList(out int pageCount, DateTime? minDate, DateTime? maxDate, string userId = null, int pageIndex = 0, int pageSize = 0)
        {
            List<WMUserBonus> list = null;
            bool isUser = !General.IsNullable(userId);
            DateTime min = (minDate.HasValue ? minDate.Value : DateTime.MinValue);
            DateTime max = (maxDate.HasValue ? maxDate.Value : DateTime.MaxValue);
            pageCount = 0;

            using (WMContext context = new WMContext())
            {
                var query = (
                    from ub in context.UserBonus
                    where (isUser ? ub.UserId.Equals(userId) : true)
                       && ub.AddDate >= min
                       && ub.AddDate <= max
                    orderby ub.AddDate descending
                    select new WMUserBonus
                    {
                        Id = ub.Id,
                        UserId = ub.UserId,
                        OrderId = ub.OrderId,
                        BonusSum = ub.BonusSum,
                        AddDate = ub.AddDate
                    }
                );

                if (query != null)
                {
                    pageCount = query.Count();

                    if (pageIndex >= 0 && pageSize > 0)
                        query = query.Skip(pageIndex * pageSize).Take(pageSize);

                    list = query.ToList();
                }
            }

            return list;
        }
Example #55
0
        public static List<WMUserIntegrals> GetList(out int pageCount, int sourceId = 0, string userId = null, int pageIndex = 0, int pageSize = 0)
        {
            List<WMUserIntegrals> list = null;
            bool flag = !General.IsNullable(userId);
            pageCount = 0;

            using (WMContext context = new WMContext())
            {
                var query = (
                    from ui in context.UserIntegrals
                    join s in context.Options on ui.SourceId equals s.Id
                    where (sourceId > 0 ? ui.SourceId.Equals(sourceId) : true)
                       && (flag ? ui.UserId.Equals(userId) : true)
                    orderby ui.AddDate descending
                    select new WMUserIntegrals
                    {
                        Id = ui.Id,
                        SourceId = ui.SourceId,
                        SourceName = s.Name,
                        UserId = ui.UserId,
                        Integral = ui.Integral,
                        AddDate = ui.AddDate
                    }
                );

                if (query != null)
                {
                    pageCount = query.Count();

                    if (pageIndex >= 0 && pageSize > 0)
                        query = query.Skip(pageIndex * pageSize).Take(pageSize);

                    list = query.ToList();
                }
            }

            return list;
        }
Example #56
0
        public static WMUserReceipts Get(string id)
        {
            WMUserReceipts receipt = null;

            if (!General.IsNullable(id))
            {
                using (WMContext context = new WMContext())
                {
                    receipt = (
                        from ur in context.UserReceipts
                        join pv in context.Regions on ur.ProvinceId equals pv.Id
                        join city in context.Regions on ur.CityId equals city.Id
                        join area in context.Regions on ur.AreaId equals area.Id
                        where ur.Id.Equals(id)
                        select new WMUserReceipts
                        {
                            Id = ur.Id,
                            UserId = ur.UserId,
                            ProvinceId = ur.ProvinceId,
                            ProvinceName = pv.Name,
                            CityId = ur.CityId,
                            CityName = city.Name,
                            AreaId = ur.AreaId,
                            AreaName = area.Name,
                            Address = ur.Address,
                            Contact = ur.Contact,
                            Phone = ur.Phone,
                            ZipCode = ur.ZipCode,
                            AddDate = ur.AddDate
                        }
                    ).FirstOrDefault();
                }
            }

            return receipt;
        }
Example #57
0
        public static WMOrderExpress Get(string id)
        {
            WMOrderExpress model = null;

            if (!General.IsNullable(id))
            {
                using (WMContext context = new WMContext())
                {
                    model = (
                        from oe in context.OrderExpress
                        where oe.Id.Equals(id)
                        select new WMOrderExpress
                        {
                            Id = oe.Id,
                            Name = oe.Name,
                            URL = oe.URL,
                            AddDate = oe.AddDate
                        }
                    ).FirstOrDefault();
                }
            }

            return model;
        }
Example #58
0
        public static WMGoodBrands Get(string id)
        {
            WMGoodBrands brand = null;

            if (!General.IsNullable(id))
            {
                using (WMContext context = new WMContext())
                {
                    brand = (
                        from gb in context.GoodBrands
                        where gb.Id.Equals(id)
                        select new WMGoodBrands
                        {
                            Id = gb.Id,
                            Name = gb.Name,
                            Logo = gb.Logo,
                            URL = gb.URL
                        }
                    ).FirstOrDefault();
                }
            }

            return brand;
        }
Example #59
0
        public bool Update(bool updatePwd = false)
        {
            if (this.Valid(true))
            {
                using (WMContext context = new WMContext())
                {
                    Users model = context.Users.Find(this.Id);

                    if (model != null)
                    {
                        model.UserName = this.UserName;
                        model.RoleId = this.RoleId;
                        model.NickName = this.NickName;
                        model.Integral = this.Integral;
                        model.Image = this.Image;
                        model.Mobile = this.Mobile;
                        model.BankCard = this.BankCard;
                        model.BankName = this.BankName;
                        model.StatusId = this.StatusId;
                        if (updatePwd)
                            model.Password = this.Password;

                        context.SaveChanges();
                        return true;
                    }
                }
            }

            return false;
        }
Example #60
0
        public bool Add()
        {
            if (this.Valid())
            {
                this.Id = General.UniqueString(this.Id);
                this.AddDate = DateTime.Now;

                using (WMContext context = new WMContext())
                {
                    Users model = new Users {
                        Id = this.Id,
                        RoleId = this.RoleId,
                        OpenId = this.OpenId,
                        UnionId = this.UnionId,
                        UserName = this.UserName,
                        Password = this.Password,
                        NickName = this.NickName,
                        Image = this.Image,
                        Mobile = this.Mobile,
                        BankCard = this.BankCard,
                        BankName = this.BankName,
                        StatusId = this.StatusId,
                        AddDate = this.AddDate
                    };

                    context.Users.Add(model);
                    context.SaveChanges();
                }

                return true;
            }

            return false;
        }