Exemplo n.º 1
0
        public bool ChangeTradeStatus(int tradeId,int newStatus)
        {
            bool result = false;

            using (AnanEntities db = new AnanEntities())
            {
                Trade trade = (from t in db.Trade where t.ID == tradeId select t).FirstOrDefault<Trade>();

                if (trade == null)
                {
                    throw new Exception("此订单不存在");
                }

                if (trade.Status == 7)
                {
                    throw new Exception("此订单已经取消,不能修改状态");
                }

                if (trade.Status == 1 && (newStatus == 3 || newStatus == 4 || newStatus ==5))
                {
                    throw new Exception("此订单没有付款,不能设为正在配货,已经发货,订单完成");
                }

                trade.Status = (short)newStatus;
                db.SaveChanges();
                result = true;
            }

            return result;
        }
Exemplo n.º 2
0
        public bool CancelTrade(int trade_id, int user_id)
        {
            bool result = false;
            using (AnanEntities db = new AnanEntities())
            {
                Trade trade=(from td in db.Trade where td.ID==trade_id select td).FirstOrDefault<Trade>();
                if (trade == null)
                {
                    throw new Exception("此订单不存在");
                }

                if (trade.UserID != user_id)
                {
                    throw new Exception("您不能取消别人的订单");
                }

                if (trade.Status != 0)
                {
                    throw new Exception("订单状态不是初始状态,无法取消,请联系客户取消。");
                }

                //7 means cancel trade
                trade.Status = 7;

                db.SaveChanges();

                result = true;
            }
            return result;
        }
Exemplo n.º 3
0
 public void SetCorpInfo(CorpInfo info)
 {
     using (AnanEntities db = new AnanEntities())
     {
         List<CorpInfo> infos = (from ci in db.CorpInfo orderby ci.ID descending select ci).ToList<CorpInfo>();
         if (infos.Count > 0)
         {
             info.ID = infos[0].ID;
             UpdateProperties(infos[0], info);
         }
         else
         {
             db.CorpInfo.Add(info);
         }
         db.SaveChanges();
     }
 }
Exemplo n.º 4
0
        public Category CreateCategory(int parentId,string name)
        {
            Category category = new Category();

            if (string.IsNullOrEmpty(name))
            {
                throw new Exception("");
            }

            category.Name = name;
            category.ParentID = parentId;
            category.Created = anan.web.Util.DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
            if(this.CurrentUser!=null)
            category.UserID = this.CurrentUser.ID;
            category.Enabled = true;

            using (AnanEntities db = new AnanEntities())
            {
                db.Category.Add(category);
                db.SaveChanges();
            }

            return category;
        }
Exemplo n.º 5
0
 public void CreateImage(Image img)
 {
     using (AnanEntities db = new AnanEntities())
     {
         img.ProductID = 0;
         if(img.Path==null)
         {
             img.Path="";
         }
         db.Image.Add(img);
         db.SaveChanges();
     }
 }
Exemplo n.º 6
0
        public bool UpdateProduct(Product product, int[] images)
        {
            bool result = false;
            using (AnanEntities db = new AnanEntities())
            {
                Product old = (from p in db.Product where p.ID == product.ID select p).FirstOrDefault<Product>();
                List<Image> imgs = null;
                List<int> newImg = new List<int>();
                if (old != null)
                {
                    product.Created = old.Created;
                    base.UpdateProperties(old, product);
                    db.SaveChanges();

                    imgs=(from i in db.Image where i.ProductID==product.ID select i).ToList<Image>();
                    for (int i = 0; i < images.Length; i++)
                    {
                        bool found = false;
                        foreach (Image im in imgs)
                        {
                            if (im.ID == images[i])
                            {
                                found = true;
                                break;
                            }
                        }

                        if (!found)
                        {
                            newImg.Add(images[i]);
                        }
                    }

                    int[] ids = newImg.ToArray<int>();
                    List<Image> igs = (from im in db.Image where ids.Contains(im.ID) select im).ToList<Image>();
                    foreach (Image i in igs)
                    {
                        i.ProductID = product.ID;
                    }

                    db.SaveChanges();

                    result = true;
                }
            }
            return result;
        }
Exemplo n.º 7
0
        public void UpdateImage(Image img)
        {
            using (AnanEntities db = new AnanEntities())
            {
                Image image = (from i in db.Image where i.ID == img.ID select i).FirstOrDefault<Image>();
                if (image != null)
                {
                    image.ProductID = img.ProductID;
                    image.Path = img.Path;
                }

                db.SaveChanges();
            }
        }
Exemplo n.º 8
0
 public bool UpdateCategoryVisibility(int category_id)
 {
     bool result = false;
     using (AnanEntities db = new AnanEntities())
     {
         Category cate = (from ca in db.Category where ca.ID == category_id select ca).FirstOrDefault<Category>();
         if (cate != null)
         {
             if ((bool)cate.Enabled)
             {
                 cate.Enabled = false;
             }
             else
             {
                 cate.Enabled = true;
             }
             db.SaveChanges();
             result = true;
         }
     }
     return result;
 }
Exemplo n.º 9
0
        public void DeleteImage(int imageId)
        {
            using (AnanEntities db = new AnanEntities())
            {
                Image image = (from i in db.Image where i.ID == imageId select i).FirstOrDefault<Image>();
                if (image != null)
                {
                    db.Image.Remove(image);
                }

                db.SaveChanges();
            }
        }
Exemplo n.º 10
0
        public bool DeleteCategory(int categoryId)
        {
            bool result = false;
            using (AnanEntities db = new AnanEntities())
            {
                Category c = (from cate in db.Category where cate.ID == categoryId select cate).FirstOrDefault<Category>();
                if (c != null)
                {
                    db.Category.Remove(c);
                    db.SaveChanges();
                    result = true;
                }
            }

            return result;
        }
Exemplo n.º 11
0
 public bool CreateAddress(int userId,int pid,int cid,int did,string addr,string person,string phone)
 {
     bool result = false;
     User_Address address = new User_Address();
     address.ProvinceID = pid;
     address.CityID = cid;
     address.DistrictID = did;
     address.Address = addr;
     address.Created = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
     address.Person = person;
     address.Phone = phone;
     address.UserID = userId;
     using (AnanEntities db = new AnanEntities())
     {
         db.User_Address.Add(address);
         db.SaveChanges();
         result = true;
     }
     return result;
 }
Exemplo n.º 12
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="user"></param>
 /// <returns></returns>
 public bool UpdateUser(User user)
 {
     bool result = false;
     using (AnanEntities db = new AnanEntities())
     {
         User dbUser=(from u in db.User where u.ID==user.ID select u).FirstOrDefault<User>();
         base.UpdateProperties(dbUser, user);
         db.SaveChanges();
         result = true;
     }
     return result;
 }
Exemplo n.º 13
0
        public bool SubmitOrder(int user_id,int address_id, List<Product> products,string desc)
        {
            bool result = false;

            if (products != null && address_id > 0)
            {
                using (AnanEntities db = new AnanEntities())
                {
                    Trade trade = new Trade();
                    trade.AddressID = address_id;
                    trade.Amount = 0;
                    trade.Created = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                    trade.ID = 0;
                    trade.Modified = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                    trade.PaidTime = 0;
                    trade.Status = 1;
                    trade.UserID = user_id;
                    if (!string.IsNullOrEmpty(desc))
                    {
                        trade.Description = desc;
                    }
                    db.Trade.Add(trade);
                    db.SaveChanges();
                    double amount = 0;
                    foreach (Product product in products)
                    {
                        Trade_Order order = new Trade_Order();
                        order.Amount = product.Price * product.Quantity;
                        order.Created = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                        order.Price = (double)product.Price;
                        order.Quantity = (int)product.Quantity;
                        order.ProductID = product.ID;
                        order.Status = 0;
                        order.TradeID = trade.ID;
                        db.Trade_Order.Add(order);
                        amount += (double)(product.Price * product.Quantity);
                    }

                    trade.Amount = amount;
                    db.SaveChanges();
                    result = true;
                }
            }

            return result;
        }
Exemplo n.º 14
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public bool LocalRegisterUser(User user)
        {
            bool result = false;
            AnanEntities db = new AnanEntities();
            try
            {
                if (string.IsNullOrEmpty(user.Email))
                {
                    throw new Exception("");
                }

                if (string.IsNullOrEmpty(user.Password))
                {
                    throw new Exception("");
                }
                user.Created = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                user.Password = Encrypt.MD5(user.Password);
                db.User.Add(user);
                db.SaveChanges();
            }
            catch
            {
            }
            finally
            {
                if (db != null)
                {
                    db.Dispose();
                }
            }
            return result;
        }
Exemplo n.º 15
0
        public bool CreateProduct(Product product,int[] images)
        {
            bool result = false;
            using (AnanEntities db = new AnanEntities())
            {
                db.Product.Add(product);
                db.SaveChanges();

                if (product.ID>0 && images != null)
                {
                    List<Image> imgs = (from im in db.Image where images.Contains(im.ID) select im).ToList<Image>();
                    foreach (Image i in imgs)
                    {
                        i.ProductID = product.ID;
                    }

                    db.SaveChanges();
                    result = true;
                }
            }
            return result;
        }
Exemplo n.º 16
0
 public bool DeleteImage(int image_id,string serverRoot)
 {
     bool result = false;
     Image image = null;
     using (AnanEntities db = new AnanEntities())
     {
         image = (from i in db.Image where i.ID == image_id select i).FirstOrDefault<Image>();
         if (image != null)
         {
             string fullPath = serverRoot+image.Path.Replace("/",@"\");
             if (System.IO.File.Exists(fullPath))
             {
                 System.IO.File.Delete(fullPath);
                 db.Image.Remove(image);
                 db.SaveChanges();
                 result = true;
             }
         }
     }
     return result;
 }
Exemplo n.º 17
0
        public bool DeleteAddress(int id,int user_id)
        {
            bool result = false;
            using (AnanEntities db = new AnanEntities())
            {
                User_Address address=(from add in db.User_Address where add.ID==id && add.UserID==user_id select add).FirstOrDefault<User_Address>();
                if (address == null)
                {

                }
                else
                {
                    db.User_Address.Remove(address);
                    db.SaveChanges();
                    result = true;
                }
            }
            return result;
        }