Example #1
0
 public string ChangeState(int id)
 {
     using (var entities = new V308CMSEntities())
     {
         var productTypeItem = (
             from item in entities.ProductType.Include("ListProduct")
             where item.ID == id
             select item
             ).FirstOrDefault();
         if (productTypeItem != null)
         {
             productTypeItem.Status = !productTypeItem.Status;
             entities.SaveChanges();
             if (productTypeItem.ListProduct != null && productTypeItem.ListProduct.Count > 0)
             {
                 foreach (var product in productTypeItem.ListProduct)
                 {
                     product.Status = productTypeItem.Status;
                     entities.SaveChanges();
                 }
             }
             return("ok");
         }
         return("not_exists");
     }
 }
Example #2
0
 public string ChangeState(int id)
 {
     using (var entities = new V308CMSEntities())
     {
         var categoryItem = (from item in entities.NewsGroups.Include("ListNews")
                             where item.ID == id
                             select item
                             ).FirstOrDefault();
         if (categoryItem != null)
         {
             categoryItem.Status = !categoryItem.Status;
             entities.SaveChanges();
             if (categoryItem.ListNews != null && categoryItem.ListNews.Count > 0)
             {
                 foreach (var news in categoryItem.ListNews)
                 {
                     news.Status = categoryItem.Status;
                     entities.SaveChanges();
                 }
             }
             return("ok");
         }
         return("not_exists");
     }
 }
Example #3
0
        public string Insert(News data)
        {
            var newsItem = (from news in entities.News
                            where news.Title == data.Title && news.TypeID == data.TypeID
                            select news).FirstOrDefault();

            if (newsItem == null)
            {
                entities.News.Add(data);
                entities.SaveChanges();
                return("ok");
            }
            return("exists");
        }
Example #4
0
        public string Delete(int id)
        {
            var configItem = (from config in _entities.SiteConfig
                              where config.id == id
                              select config).FirstOrDefault();

            if (configItem != null)
            {
                _entities.SiteConfig.Remove(configItem);
                _entities.SaveChanges();
                return("ok");
            }
            return("not_exists");
        }
Example #5
0
        public string Delete(int id)
        {
            using (var entities = new V308CMSEntities())
            {
                var productTypeItem = (
                    from item in entities.ProductType.Include("ListProduct")
                    where item.ID == id
                    select item
                    ).FirstOrDefault();
                if (productTypeItem != null)
                {
                    if (productTypeItem.ListProduct != null && productTypeItem.ListProduct.Count > 0)
                    {
                        foreach (var product in productTypeItem.ListProduct)
                        {
                            entities.Product.Remove(product);
                            entities.SaveChanges();
                        }
                    }
                    entities.ProductType.Remove(productTypeItem);
                    entities.SaveChanges();
                    var listSubType = (
                        from item in entities.ProductType.Include("ListProduct")
                        where item.ID == productTypeItem.ID
                        select item
                        ).ToList();
                    if (listSubType.Count > 0)
                    {
                        foreach (var subType in listSubType)
                        {
                            if (subType.ListProduct != null && subType.ListProduct.Count > 0)
                            {
                                foreach (var product in subType.ListProduct)
                                {
                                    entities.Product.Remove(product);
                                    entities.SaveChanges();
                                }
                            }
                            entities.ProductType.Remove(subType);
                            entities.SaveChanges();
                        }
                    }
                    return("ok");
                }
                return("not_exists");
            }

            return("not_exists");
        }
Example #6
0
        public void update(int uid = 0)
        {
            try
            {
                var visister = new Visister();
                visister.ip_address = HttpContext.Current.Request.UserHostAddress;
                visister.ip_address = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
                visister.useragent  = System.Web.HttpContext.Current.Request.UserAgent;
                visister.platform   = System.Web.HttpContext.Current.Request.Browser.Platform;
                visister.browser    = System.Web.HttpContext.Current.Request.Browser.Id;

                visister.timestamp = DateTime.Now;
                visister.host      = System.Web.HttpContext.Current.Request.Url.Host;
                visister.uid       = uid;

                var item = from v in entities.VisisterTbl where v.ip_address == visister.ip_address select v;
                if (item.Count() < 1)
                {
                    entities.VisisterTbl.Add(visister);
                    entities.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                Console.Write(ex);
                throw;
            }
        }
Example #7
0
 public string Update(int id, string name, int parentId, string icon, string description, string image, string imageBanner,
                      int number, DateTime createdDate, bool status, bool isHome)
 {
     using (var entities = new V308CMSEntities())
     {
         var productType = (from type in entities.ProductType
                            where type.ID == id
                            select type
                            ).FirstOrDefault();
         if (productType != null)
         {
             productType.Name        = name;
             productType.Parent      = parentId;
             productType.Icon        = icon;
             productType.Description = description;
             if (!string.IsNullOrWhiteSpace(image) && productType.Image != image)
             {
                 productType.Image = image;
             }
             if (!string.IsNullOrWhiteSpace(imageBanner) && productType.ImageBanner != imageBanner)
             {
                 productType.ImageBanner = imageBanner;
             }
             productType.Number = number;
             productType.Date   = createdDate;
             productType.Status = status;
             productType.IsHome = isHome;
             entities.SaveChanges();
             return("ok");
         }
         return("not_exists");
     }
 }
Example #8
0
        public string Insert(string url, int uid, string source = "", string taget = "", string name = "", string summary = "")
        {
            try
            {
                var link = new AffiliateLink
                {
                    url        = url,
                    code       = HashCode(),
                    source     = source,
                    taget      = taget,
                    name       = name,
                    summary    = summary,
                    created    = DateTime.Now,
                    created_by = uid
                };
                entities.AffiliateLink.Add(link);
                entities.SaveChanges();

                return(link.ID.ToString());
            }
            catch (Exception ex)
            {
                return(ex.ToString());
            }
        }
Example #9
0
 public string Insert(string name, int parentId, int number, bool state, DateTime date)
 {
     using (var entities = new V308CMSEntities())
     {
         var checkCategory = (from item in entities.NewsGroups
                              where item.Parent == parentId && item.Name == name
                              select item
                              ).FirstOrDefault();
         if (checkCategory == null)
         {
             var newsCategory = new NewsGroups
             {
                 Name   = name,
                 Parent = parentId,
                 Number = number,
                 Status = state,
                 Date   = date
             };
             entities.NewsGroups.Add(newsCategory);
             entities.SaveChanges();
             return("ok");
         }
         return("exists");
     }
 }
Example #10
0
 public string Insert(NewsGroups category)
 {
     using (var entities = new V308CMSEntities())
     {
         var checkCategory = (from item in entities.NewsGroups
                              where item.Parent == category.Parent && item.Name == category.Name
                              select item
                              ).FirstOrDefault();
         if (checkCategory == null)
         {
             var newsCategory = new NewsGroups
             {
                 Name   = category.Name,
                 Parent = category.Parent,
                 Number = category.Number,
                 Status = category.Status,
                 Date   = category.Date
             };
             entities.NewsGroups.Add(newsCategory);
             entities.SaveChanges();
             return("ok");
         }
         return("exists");
     }
 }
Example #11
0
 public string Delete(int id)
 {
     using (var entities = new V308CMSEntities())
     {
         var categoryItem = (
             from item in entities.NewsGroups.Include("ListNews")
             where item.ID == id
             select item
             ).FirstOrDefault();
         if (categoryItem != null)
         {
             if (categoryItem.ListNews != null && categoryItem.ListNews.Count > 0)
             {
                 foreach (var news in categoryItem.ListNews)
                 {
                     entities.News.Remove(news);
                     entities.SaveChanges();
                 }
             }
             entities.NewsGroups.Remove(categoryItem);
             entities.SaveChanges();
             var listSubCategory = (
                 from item in entities.NewsGroups.Include("ListNews")
                 where item.ID == categoryItem.ID
                 select item
                 ).ToList();
             if (listSubCategory.Count > 0)
             {
                 foreach (var subCategory in listSubCategory)
                 {
                     if (subCategory.ListNews != null && subCategory.ListNews.Count > 0)
                     {
                         foreach (var news in subCategory.ListNews)
                         {
                             entities.News.Remove(news);
                             entities.SaveChanges();
                         }
                     }
                     entities.NewsGroups.Remove(subCategory);
                     entities.SaveChanges();
                 }
             }
             return("ok");
         }
         return("not_exists");
     }
 }
Example #12
0
        public string AddItemToWishlist(int productId, string userId)
        {
            var wishlistItem = (from item in _entities.ProductWishlist
                                where item.UserId == userId
                                select item
                                ).FirstOrDefault();

            if (wishlistItem != null)
            {
                if (string.IsNullOrWhiteSpace(wishlistItem.ListProduct))
                {
                    wishlistItem.ListProduct = productId.ToString();
                    _entities.SaveChanges();
                    return("ok");
                }
                if (wishlistItem.ListProduct.Contains(";"))
                {
                    if (wishlistItem.ListProduct.Contains(";" + productId) ||
                        wishlistItem.ListProduct.Contains(productId + ";"))
                    {
                        return("exist");
                    }
                }
                if (wishlistItem.ListProduct.Contains(productId.ToString()))
                {
                    return("exist");
                }

                wishlistItem.ListProduct = wishlistItem.ListProduct + ";" + productId;
                _entities.SaveChanges();
                return("ok");
            }
            else
            {
                var newWishList = new ProductWishlist
                {
                    ListProduct = productId.ToString(),
                    UserId      = userId
                };
                _entities.ProductWishlist.Add(newWishList);
                _entities.SaveChanges();
                return("ok");
            }
        }
Example #13
0
        public string Insert(string email, string password, string salt, string token, DateTime tokenExpireDate)
        {
            var accounts = from p in entities.Account
                           where p.Email.Equals(email) || p.UserName.Equals(email)
                           select p;

            if (accounts != null || accounts.Count() < 1)
            {
                return("exist");
            }
            else
            {
                var checkAccount = accounts.FirstOrDefault();
                var mAccount     = new Account()
                {
                    Email           = email,
                    UserName        = email,
                    Password        = HashPassword(password, salt),
                    Salt            = salt,
                    Token           = token,
                    TokenExpireDate = tokenExpireDate,
                    Status          = false
                };
                entities.Account.Add(mAccount);
                entities.SaveChanges();
                return("ok");
            }
        }
Example #14
0
 public string Insert(string fullName, string email, string phone, string message, DateTime createdDate)
 {
     using (var entities = new V308CMSEntities())
     {
         var contact = new Contact
         {
             FullName    = fullName,
             Email       = email,
             Phone       = phone,
             Message     = message,
             CreatedDate = createdDate
         };
         entities.Contact.Add(contact);
         entities.SaveChanges();
         return("ok");
     }
 }
Example #15
0
 public string Update(int id, string name, int parentId, int number, bool state, DateTime createdDate)
 {
     using (var entities = new V308CMSEntities())
     {
         var newsCategory = (from item in entities.NewsGroups
                             where item.ID == id
                             select item).FirstOrDefault();
         if (newsCategory != null)
         {
             newsCategory.Name   = name;
             newsCategory.Parent = parentId;
             newsCategory.Number = number;
             newsCategory.Status = state;
             newsCategory.Date   = createdDate;
             entities.SaveChanges();
             return("ok");
         }
         return("not_exists");
     }
 }
Example #16
0
 public string Insert(
     string name,
     int parentId,
     string icon,
     string description,
     string image,
     string imageBanner,
     int number,
     DateTime createdDate,
     bool status,
     bool isHome
     )
 {
     using (var entities = new V308CMSEntities())
     {
         var checkProductType = (from type in entities.ProductType
                                 where type.Name == name && type.Parent == parentId
                                 select type
                                 ).FirstOrDefault();
         if (checkProductType == null)
         {
             var newProductType = new ProductType
             {
                 Name        = name,
                 Parent      = parentId,
                 Icon        = icon,
                 Description = description,
                 Image       = image,
                 ImageBanner = imageBanner,
                 Number      = number,
                 Date        = createdDate,
                 Status      = status,
                 IsHome      = isHome
             };
             entities.ProductType.Add(newProductType);
             entities.SaveChanges();
             return("ok");
         }
         return("exists");
     }
 }
Example #17
0
        public string Insert(string title, string content, int created_by)
        {
            try
            {
                var TicketNew = new Ticket
                {
                    title      = title,
                    content    = content,
                    created_by = created_by,
                    created    = DateTime.Now
                };
                entities.TicketRepository.Add(TicketNew);
                entities.SaveChanges();

                return(TicketNew.ID.ToString());
            }
            catch (Exception ex)
            {
                return(ex.ToString());
            }
        }
Example #18
0
 public string Update(NewsGroups category)
 {
     using (var entities = new V308CMSEntities())
     {
         var newsCategory = (from item in entities.NewsGroups
                             where item.ID == category.ID
                             select item
                             ).FirstOrDefault();
         if (newsCategory != null)
         {
             newsCategory.Name   = category.Name;
             newsCategory.Parent = category.Parent;
             newsCategory.Number = category.Number;
             newsCategory.Status = category.Status;
             newsCategory.Date   = category.Date;
             entities.SaveChanges();
             return("ok");
         }
         return("not_exists");
     }
 }
Example #19
0
 public string Update(int id, string fullName, string email, string phone, string message, DateTime createdDate)
 {
     using (var entities = new V308CMSEntities())
     {
         var contactUpdate = (from contact in entities.Contact
                              where contact.ID == id
                              select contact
                              ).FirstOrDefault();
         if (contactUpdate != null)
         {
             contactUpdate.FullName    = fullName;
             contactUpdate.Email       = email;
             contactUpdate.Phone       = phone;
             contactUpdate.Message     = message;
             contactUpdate.CreatedDate = createdDate;
             entities.SaveChanges();
             return("ok");
         }
         return("not_exists");
     }
 }
Example #20
0
        public string Insert(int OrderID, int ItemID, string ItemName, double price, int quantity)
        {
            try
            {
                var item = new productorder_detail
                {
                    order_id   = OrderID,
                    item_id    = ItemID,
                    item_name  = ItemName,
                    item_price = price,
                    item_qty   = quantity
                };
                entities.ProductOrderItem.Add(item);
                entities.SaveChanges();

                return(item.ID.ToString());
            }
            catch (Exception ex)
            {
                return(ex.ToString());
            }
        }
Example #21
0
        public string Insert(string Address, string email, string fullName, int item_count = 0, double totalAmount = 0)
        {
            try{
                var order = new ProductOrder
                {
                    FullName = fullName,
                    Address  = Address,
                    Email    = email,
                    Price    = totalAmount,
                    Count    = item_count,
                    Date     = DateTime.Now
                };
                entities.ProductOrder.Add(order);
                entities.SaveChanges();

                return(order.ID.ToString());
            }
            catch (Exception ex)
            {
                return(ex.ToString());
            }
        }
Example #22
0
        public string Insert(string image, string title, string summary, string url)
        {
            try
            {
                var banner = new AffiliateBanner
                {
                    image   = image,
                    title   = title,
                    summary = summary,
                    url     = url,

                    created = DateTime.Now
                };
                entities.AffiliateBanner.Add(banner);
                entities.SaveChanges();

                return(banner.ID.ToString());
            }
            catch (Exception ex)
            {
                return(ex.ToString());
            }
        }