public static ProductsModel GetRandomPro()
    {
        ProductsModel pro = new ProductsModel();
        try
        {

            using (DataContentDataContext dc = new DataContentDataContext())
            {
                var items = (from temp in dc.Products
                             select temp);
                int count = items.Count(); // 1st round-trip
                int index = new Random().Next(count);
                Product i = items.Skip(index).FirstOrDefault();
                ProductsModel p = new ProductsModel(i.Id, i.Header, i.Name, i.Descrition, i.Price, i.Link_Image_Small, i.Link_Image, i.Creater, i.CreateDate, i.Modifier, i.ModifyDate);
                pro = p;

            }
            return pro;
        }
        catch (Exception)
        {
            return pro;

        }
    }
示例#2
0
    public static int Insert(UserLogsModel model)
    {
        try
        {
            using (DataContentDataContext dc = new DataContentDataContext())
            {
                User_Log newItem = new User_Log();
                newItem.ID = model.ID;
                newItem.Functions = model.Functions;

                newItem.ItemID = model.ItemID;
                newItem.UserID = model.UserID;
                newItem.UserName = model.UserName;
                newItem.Creater = model.Creater;
                newItem.CreateDate = model.CreateDate;

                dc.User_Logs.InsertOnSubmit(newItem);
                dc.SubmitChanges();

            }
            return 1;
        }
        catch (Exception)
        {
            return 0;

        }
    }
    public static int Insert(ProductsModel model)
    {
        try
        {
            using (DataContentDataContext dc = new DataContentDataContext())
            {
                Product newItem = new Product();
                newItem.Id = model.ID;
                newItem.Header = model.Header;
                newItem.Descrition = model.Descrition;
                newItem.Name = model.Name;
                newItem.Link_Image = model.Link_Image;
                newItem.Link_Image_Small = model.Link_Image_Small;
                newItem.Price = model.Price;
                newItem.Creater = model.Creater;
                newItem.CreateDate = model.CreateDate;
                newItem.Modifier = model.Modifier;
                newItem.ModifyDate = model.ModifyDate;
                dc.Products.InsertOnSubmit(newItem);
                dc.SubmitChanges();

            }
            return 1;
        }
        catch (Exception)
        {
            return 0;

        }
    }
示例#4
0
    public static int Insert(NewsModel model)
    {
        try
        {
            using (DataContentDataContext dc = new DataContentDataContext())
            {
                New newItem = new New();
                newItem.Id = model.ID;
                newItem.Title = model.Title;
                newItem.Header = model.Header;
                newItem.Contents = model.Contents;
                newItem.Author = model.Author;
                newItem.Link_Image = model.Link_Image;
                newItem.Link_Image_Small = model.Link_Image_Small;
                newItem.Type_News = model.Type_News;
                newItem.Poster = model.Poster;
                newItem.PosterID = model.PosterID;
                newItem.Creater = model.Creater;
                newItem.CreateDate = model.CreateDate;
                newItem.Modifier = model.Modifier;
                newItem.ModifyDate = model.ModifyDate;
                dc.News.InsertOnSubmit(newItem);
                dc.SubmitChanges();

            }
            return 1;
        }
        catch (Exception)
        {
            return 0;

        }
    }
 public static int Insert(EmployeeModel model)
 {
     try
     {
         using (DataContentDataContext dc = new DataContentDataContext())
         {
             Employee emp = new Employee();
             emp.Id = model.ID;
             emp.EmployeeName = model.EmployeeName;
             emp.Username = model.Username;
             emp.Password = model.Password;
             emp.Creater = model.Creater;
             emp.CreateDate = model.CreateDate;
             emp.Modifier = model.Modifier;
             emp.ModifyDate = model.ModifyDate;
             dc.Employees.InsertOnSubmit(emp);
             dc.SubmitChanges();
         }
         return 1;
     }
     catch (Exception)
     {
         return 0;
     }
 }
    /// <summary>
    /// Insert new Item for Solutions.
    /// </summary>
    /// <param name="model"></param>
    /// <returns></returns>
    public static int Insert(SolutionsModel model)
    {
        try
        {
            using (DataContentDataContext dc = new DataContentDataContext())
            {
                Solution newItem = new Solution();
                newItem.ID = model.ID;
                newItem.Name = model.Name;
                newItem.Header = model.Header;
                newItem.Contents = model.Contents;
                newItem.Link_Image = model.Link_Image;
                newItem.Link_Image_Small = model.Link_Image_Small;
                newItem.Type_Solution = model.Type_Solution;
                newItem.Creater = model.Creater;
                newItem.CreateDate = model.CreateDate;
                newItem.Modifier = model.Modifier;
                newItem.ModifyDate = model.ModifyDate;
                dc.Solutions.InsertOnSubmit(newItem);
                dc.SubmitChanges();

            }
            return 1;
        }
        catch (Exception)
        {
            return 0;

        }
    }
 public static EmployeeModel SelectOne(EmployeeModel model)
 {
     try
     {
         using (DataContentDataContext dc = new DataContentDataContext())
         {
             Employee item = dc.Employees.Where(a => a.Id == model.ID).SingleOrDefault();
             return new EmployeeModel(item.Id, item.EmployeeName, item.RoleId.ToString(), item.Username, item.Password, item.Creater, item.CreateDate, item.Modifier, item.ModifyDate);
         }
     }
     catch (Exception)
     {
         return new EmployeeModel();
     }
 }
    /// <summary>
    /// Get max view of Services.
    /// </summary>
    /// <returns></returns>
    public static int getMaxView()
    {
        try
        {
            using (DataContentDataContext dc = new DataContentDataContext())
            {
                var maxValue = dc.Services.Max(s => s.ServiceView);
                return (int)maxValue;
            }
        }
        catch (Exception)
        {

            return 0;
        }
    }
    public static int Delete(Employee model)
    {
        try
        {
            using (DataContentDataContext dc = new DataContentDataContext())
            {
                Employee deleteItem = dc.Employees.Where(a => a.Id == model.Id).SingleOrDefault();
                dc.Employees.DeleteOnSubmit(deleteItem);
                dc.SubmitChanges();
            }
            return 1;
        }
        catch (Exception)
        {

            return 0;
        }
    }
示例#10
0
    public static int Delete(NewsModel model)
    {
        try
        {
            using (DataContentDataContext dc = new DataContentDataContext())
            {
                New delItem = dc.News.Where(a => a.Id == model.ID).SingleOrDefault();
                dc.News.DeleteOnSubmit(delItem);
                dc.SubmitChanges();
            }
            return 1;
        }
        catch (Exception)
        {

            return 0;
        }
    }
示例#11
0
    /// <summary>
    /// Get News base on CatID
    /// </summary>
    /// <param name="CatID"></param>
    /// <returns></returns>
    public static List<NewsModel> SelectAll(string CatID)
    {
        List<NewsModel> lst = new List<NewsModel>();
        try
        {
            using (DataContentDataContext dc = new DataContentDataContext())
            {

                var items = from temp in dc.News
                            where temp.CatID == CatID
                            select temp;

                foreach (var i in items)
                {
                    NewsModel n = new NewsModel(i.Id, i.Header, i.Contents, i.Author, i.Type_News,
                        i.Link_Image_Small, i.Link_Image, i.Poster, i.PosterID, i.Creater, i.CreateDate,
                        i.Modifier, i.ModifyDate, i.Title);
                    lst.Add(n);
                }
            }
            return lst;
        }
        catch (Exception)
        {
            return lst;

        }
    }
示例#12
0
    public static int Update(Employee model)
    {
        try
        {
            using (DataContentDataContext dc = new DataContentDataContext())
            {
                Employee changeItem = dc.Employees.Where(a => a.Id == model.Id).SingleOrDefault();
                changeItem.EmployeeName = model.EmployeeName;
                changeItem.Modifier = model.Modifier;
                changeItem.ModifyDate = model.ModifyDate;
                dc.SubmitChanges();
            }
            return 1;
        }
        catch (Exception)
        {

            return 0;
        }
    }
示例#13
0
    public static int Update(NewsModel model)
    {
        try
        {
            using (DataContentDataContext dc = new DataContentDataContext())
            {
                New changeItem = dc.News.Where(a => a.Id == model.ID).SingleOrDefault();
                changeItem.Header = model.Header;
                changeItem.Title = model.Title;
                changeItem.Contents = model.Contents;
                changeItem.Author = model.Author;
                changeItem.Type_News = model.Type_News;
                changeItem.Link_Image = model.Link_Image;
                changeItem.Link_Image_Small = model.Link_Image_Small;
                changeItem.ModifyDate = model.ModifyDate;
                changeItem.Modifier = model.Modifier;
                changeItem.PosterID = model.PosterID;
                changeItem.Poster = model.Poster;
                dc.SubmitChanges();
            }
            return 1;
        }
        catch (Exception)
        {

            return 0;
        }
    }
示例#14
0
    /// <summary>
    /// Select top Like service.
    /// </summary>
    /// <returns></returns>
    public static ServicesModel SelectTopLikeService()
    {
        try
        {
            using (DataContentDataContext dc = new DataContentDataContext())
            {
                ServicesModel s = null;
                var items = (from sv in dc.Services
                             select sv);
                int count = items.Count(); // 1st round-trip
                int index = new Random().Next(count);
                var result = items.Skip(index).Take(1);
                foreach (var i in result)
                {
                    s = new ServicesModel(i.Id, i.Header, i.Name, i.Descrition, i.Price, i.Link_Image_Small, i.Link_Image, i.Type_Services, i.Creater, i.CreateDate, i.Modifier, i.ModifyDate);
                }
                return s;
            }
        }
        catch (Exception)
        {

            return new ServicesModel();
        }
    }
示例#15
0
    public static NewsModel SelectOne(NewsModel model)
    {
        try
        {
            using (DataContentDataContext dc = new DataContentDataContext())
            {
                New i = dc.News.Where(a => a.Id == model.ID).SingleOrDefault();
                return new NewsModel(i.Id, i.Header, i.Contents, i.Author, i.Type_News, i.Link_Image_Small,
                    i.Link_Image, i.Poster, i.PosterID, i.Creater, i.CreateDate, i.Modifier, i.ModifyDate, i.Title);
            }
        }
        catch (Exception)
        {

            return new NewsModel();
        }
    }
示例#16
0
    public static int Update(ProductsModel model)
    {
        try
        {
            using (DataContentDataContext dc = new DataContentDataContext())
            {
                Product changeItem = dc.Products.Where(a => a.Id == model.ID).SingleOrDefault();
                changeItem.Header = model.Header;
                changeItem.Name = model.Name;
                changeItem.Price = model.Price;
                changeItem.Descrition = model.Descrition;
                changeItem.Link_Image = model.Link_Image;
                changeItem.Link_Image_Small = model.Link_Image_Small;
                changeItem.ModifyDate = model.ModifyDate;
                changeItem.Modifier = model.Modifier;
                dc.SubmitChanges();
            }
            return 1;
        }
        catch (Exception)
        {

            return 0;
        }
    }
示例#17
0
    /// <summary>
    /// Select top view service.
    /// </summary>
    /// <returns></returns>
    public static ServicesModel SelectTopViewService()
    {
        try
        {
            using (DataContentDataContext dc = new DataContentDataContext())
            {
                ServicesModel s = null;
                var items = dc.Services.Where(a => a.ServiceView == getMaxView()).Take(1);
                foreach (var i in items)
                {
                    s = new ServicesModel(i.Id, i.Header, i.Name, i.Descrition, i.Price, i.Link_Image_Small, i.Link_Image, i.Type_Services, i.Creater, i.CreateDate, i.Modifier, i.ModifyDate);
                }
                return s;
            }
        }
        catch (Exception)
        {

            return new ServicesModel();
        }
    }
示例#18
0
    public static ProductsModel SelectOne(ProductsModel model)
    {
        try
        {
            using (DataContentDataContext dc = new DataContentDataContext())
            {
                Product i = dc.Products.Where(a => a.Id == model.ID).SingleOrDefault();
                return new ProductsModel(i.Id, i.Header, i.Name, i.Descrition, i.Price, i.Link_Image_Small, i.Link_Image, i.Creater, i.CreateDate, i.Modifier, i.ModifyDate);
            }
        }
        catch (Exception)
        {

            return new ProductsModel();
        }
    }
示例#19
0
    /// <summary>
    /// Select top product to view in default page.
    /// </summary>
    /// <param name="top"></param>
    /// <returns></returns>
    public static List<ProductsModel> SelectTopProduct(int top)
    {
        List<ProductsModel> lst = new List<ProductsModel>();
        try
        {
            using (DataContentDataContext dc = new DataContentDataContext())
            {
                var items = (from temp in dc.Products
                            select temp).Take(top);
                foreach (var i in items)
                {
                    ProductsModel n = new ProductsModel(i.Id, i.Header, i.Name, i.Descrition, i.Price, i.Link_Image_Small, i.Link_Image, i.Creater, i.CreateDate, i.Modifier, i.ModifyDate);
                    lst.Add(n);
                }
            }
            return lst;
        }
        catch (Exception)
        {
            return lst;

        }
    }
示例#20
0
    /// <summary>
    /// Update ServiceView when user click to Service item.
    /// </summary>
    /// <param name="Id"></param>
    /// <returns></returns>
    public static int UpdateView(string Id)
    {
        try
        {
            using (DataContentDataContext dc = new DataContentDataContext())
            {
                Service changeItem = dc.Services.Where(s => s.Id == Id).SingleOrDefault();
                changeItem.ServiceView = changeItem.ServiceView + 1;
                dc.SubmitChanges();
            }
            return 1;
        }
        catch (Exception)
        {

            return 0;
        }
    }
示例#21
0
    /// <summary>
    /// Get all Solution Item.
    /// </summary>
    /// <returns></returns>
    public static List<SolutionsModel> SelectAll()
    {
        List<SolutionsModel> lst = new List<SolutionsModel>();
        try
        {
            using (DataContentDataContext dc = new DataContentDataContext())
            {
                var items = from temp in dc.Solutions
                            select temp;
                foreach (var i in items)
                {
                    SolutionsModel n = new SolutionsModel(i.ID, i.Name, i.Header, i.Contents, i.Link_Image_Small, i.Link_Image, i.Type_Solution, i.Creater, i.CreateDate, i.Modifier, i.ModifyDate);
                    lst.Add(n);
                }
            }
            return lst;
        }
        catch (Exception)
        {
            return lst;

        }
    }
示例#22
0
    /// <summary>
    /// Update new information for Solution Item
    /// </summary>
    /// <param name="model"></param>
    /// <returns></returns>
    public static int Update(SolutionsModel model)
    {
        try
        {
            using (DataContentDataContext dc = new DataContentDataContext())
            {
                Solution changeItem = dc.Solutions.Where(a => a.ID == model.ID).SingleOrDefault();
                changeItem.Header = model.Header;
                changeItem.Name = model.Name;
                changeItem.Contents = model.Contents;
                changeItem.Type_Solution = model.Type_Solution;
                changeItem.Link_Image = model.Link_Image;
                changeItem.Link_Image_Small = model.Link_Image_Small;
                changeItem.ModifyDate = model.ModifyDate;
                changeItem.Modifier = model.Modifier;
                dc.SubmitChanges();
            }
            return 1;
        }
        catch (Exception)
        {

            return 0;
        }
    }
示例#23
0
    public static List<SolutionsModel> SelectTopService(string catID, int top)
    {
        List<SolutionsModel> lst = new List<SolutionsModel>();
        try
        {
            using (DataContentDataContext dc = new DataContentDataContext())
            {
                var items = (from temp in dc.Solutions
                             where temp.Type_Solution == catID.ToCharArray()[0]
                             select temp).Take(top);
                foreach (var i in items)
                {
                    SolutionsModel n = new SolutionsModel(i.ID, i.Name, i.Header, i.Contents, i.Link_Image_Small, i.Link_Image, i.Type_Solution, i.Creater, i.CreateDate, i.Modifier, i.ModifyDate);
                    lst.Add(n);
                }
            }
            return lst;
        }
        catch (Exception)
        {

            return lst;
        }
    }
示例#24
0
    /// <summary>
    /// get one Solution Item.
    /// </summary>
    /// <param name="model"></param>
    /// <returns></returns>
    public static SolutionsModel SelectOne(SolutionsModel model)
    {
        try
        {
            using (DataContentDataContext dc = new DataContentDataContext())
            {
                Solution i = dc.Solutions.Where(a => a.ID == model.ID).SingleOrDefault();
                return new SolutionsModel(i.ID, i.Name, i.Header, i.Contents, i.Link_Image_Small, i.Link_Image, i.Type_Solution, i.Creater, i.CreateDate, i.Modifier, i.ModifyDate);
            }
        }
        catch (Exception)
        {

            return new SolutionsModel();
        }
    }