コード例 #1
0
ファイル: ProductInfo.cs プロジェクト: mainam/SoftwareSoft
        public static bool DeleteProduct(string name, List <int> arrid)
        {
            using (var context = new ProductDbFullDataContext())
            {
                var user = context.tbUsers.SingleOrDefault(x => x.UserName.Equals(name));
                if (user == null)
                {
                    throw new Exception("Vui lòng đăng nhập");
                }

                bool isAdmin = user != null && user.TypeUser == 1;
                foreach (var id in arrid)
                {
                    var data = context.tbSoftwares.SingleOrDefault(x => x.Id == id);
                    if (data == null)
                    {
                        throw new Exception("Không tìm thấy thông tin sản phẩm");
                    }
                    if (!isAdmin && data.UpBy != name)
                    {
                        throw new Exception("Bạn không thể xóa phần mềm của người khác");
                    }
                    context.tbSoftwares.DeleteOnSubmit(data);
                }
                context.SubmitChanges();
                return(true);
            }
        }
コード例 #2
0
 public static object getAll()
 {
     using (var context = new ProductDbFullDataContext())
     {
         return(context.tbSoftwaraStatus.Select(x => new { x.Name, x.Id }).ToList());
     }
 }
コード例 #3
0
ファイル: ProductInfo.cs プロジェクト: mainam/SoftwareSoft
 public static object GetBySeller(string seller, int type, int currentpage, int numberinpage, string keyword, ref int totalitem)
 {
     using (var context = new ProductDbFullDataContext())
     {
         keyword = keyword.ToLower().Trim();
         var list = context.tbSoftwares.Where(x => x.UpBy.Equals(seller) && (type == 0 || type == x.Status)).ToList();
         totalitem = list.Count;
         if (String.IsNullOrWhiteSpace(keyword))
         {
             return(list.Skip((currentpage - 1) * numberinpage).Take(numberinpage).Select(x => new
             {
                 x.Id,
                 SellerName = x.tbUser.FullName,
                 SellerId = x.UpBy,
                 x.Status,
                 StatusName = x.tbSoftwaraStatus.Name,
                 x.Price,
                 x.Name,
                 x.NumberGuaranteeDate,
                 x.Discount,
                 Category = x.tbCategory.Name,
                 ClosedDate = x.CloseDate.HasValue ? x.CloseDate.Value.ToString("dd/MM/yyyy") : ""
             }).ToList());
         }
         list = list.FindAll(x =>
                             x.Name.ToLower().Contains(keyword));
         totalitem = list.Count;
         return(list.Skip((currentpage - 1) * numberinpage).Take(numberinpage).Select(x => new
         {
             x.Id,
             SellerName = x.tbUser.FullName,
             SellerId = x.UpBy,
             x.Status,
             x.Price,
             x.Name,
             StatusName = x.tbSoftwaraStatus.Name,
             x.NumberGuaranteeDate,
             x.Discount,
             Category = x.tbCategory.Name
         }).ToList());
     }
 }
コード例 #4
0
        public static string Save(int id, string ten, decimal gia, int baohanh, int giamgia, int chuyenmuc, int status, String fileUrl, String avatarUrl, String motasanpham)
        {
            try
            {
                using (var context = new ProductDbFullDataContext())
                {
                    var username = HttpContext.Current.User.Identity.Name;
                    var user     = context.tbUsers.SingleOrDefault(x => x.UserName.Equals(username));
                    if (user == null)
                    {
                        throw new Exception("Đăng nhập đế sử dụng");
                    }
                    if (user.TypeUser == 2)
                    {
                        throw new Exception("Bạn không có quyền sử dụng chức năng này");
                    }
                    if (id != 0)
                    {
                        var sanpham = context.tbSoftwares.SingleOrDefault(x => x.Id == id);
                        if (sanpham == null)
                        {
                            throw new Exception("Không tìm thấy thông tin sản phẩm trong hệ thống");
                        }
                        if (sanpham.UpBy != username && user.TypeUser != 1)
                        {
                            throw new Exception("Bạn không có quyền sử dụng chức năng này");
                        }
                        sanpham.Name                = ten;
                        sanpham.Price               = gia;
                        sanpham.Link                = fileUrl;
                        sanpham.ImageUrl            = avatarUrl;
                        sanpham.Description         = sanpham.ShortDescription = motasanpham;
                        sanpham.Status              = status;
                        sanpham.NumberGuaranteeDate = baohanh;
                        sanpham.Discount            = giamgia;
                        if (status == 2)
                        {
                            sanpham.CloseDate = DateTime.Now;
                        }
                        else
                        {
                            sanpham.CloseDate = null;
                        }
                        sanpham.CategoryId = chuyenmuc;
                        context.SubmitChanges();
                    }
                    else
                    {
                        var sanpham = new DataAccess.Db.Product.ProductDbFull.tbSoftware()
                        {
                            CategoryId          = chuyenmuc,
                            Description         = motasanpham,
                            Discount            = giamgia,
                            ShortDescription    = motasanpham,
                            Link                = fileUrl,
                            ImageUrl            = avatarUrl,
                            Price               = gia,
                            UpBy                = username,
                            Status              = status,
                            NumberGuaranteeDate = baohanh,
                            Name                = ten,
                            CloseDate           = DateTime.Now
                        };
                        if (status != 2)
                        {
                            sanpham.CloseDate = null;
                        }
                        context.SubmitChanges();
                    }

                    return(new JavaScriptSerializer().Serialize(new { Status = true }));
                }
            }
            catch (Exception e)
            {
                return(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(new { Status = false, Data = e.Message }));
            }
        }