コード例 #1
0
        public ActionResult Search(SearchModel model)
        {
            DBModelContainer db = new DBModelContainer();

            List <Production> prs = (from p in db.Products
                                     join pDetail in db.ProductDetails on p.ProductId equals pDetail.ProductId
                                     where p.CategoryId == model.CategoryId
                                     select new
            {
                p,
                pDetail
            } into t1

                                     group t1 by t1.p.ProductId into g
                                     select new Production()
            {
                ProductId = g.Key,
                ProductionName = g.FirstOrDefault().p.Name,
                Description = g.FirstOrDefault().p.Description,
                MinPrice = g.Min(m => m.pDetail.Price),
                MaxPrice = g.Max(m => m.pDetail.Price),
                Picture = g.FirstOrDefault().pDetail.Picture,
                Color = g.FirstOrDefault().pDetail.Color
            }).ToList();

            int pageSize   = 16;
            int pageNumber = 1;

            return(PartialView("Index", prs.ToPagedList(pageNumber, pageSize)));
        }
コード例 #2
0
        public object Add(string TransactionID, string SerialNumber)
        {
            Guid pairID = Guid.NewGuid();

            using (DBModelContainer context = new DBModelContainer())
            {
                context.ProductKeyIDSerialNumberPairs.Add(new ProductKeyIDSerialNumberPairs()
                {
                    PairID        = pairID,
                    TransactionID = TransactionID,
                    SerialNumber  = SerialNumber,
                    CreationTime  = DateTime.Now,
                    SeriesID      = ((this.Parameters.ContainsKey("SeriesID")) && (this.Parameters["SeriesID"] != null)) ? this.Parameters["SeriesID"].ToString() : "",
                    SeriesName    = ((this.Parameters.ContainsKey("SeriesName")) && (this.Parameters["SeriesName"] != null)) ? this.Parameters["SeriesName"].ToString() : "",
                    ModelID       = ((this.Parameters.ContainsKey("ModelID")) && (this.Parameters["ModelID"] != null)) ? this.Parameters["ModelID"].ToString() : "",
                    ModelName     = ((this.Parameters.ContainsKey("ModelName")) && (this.Parameters["ModelName"] != null)) ? this.Parameters["ModelName"].ToString() : "",
                    DeviceID      = ((this.Parameters.ContainsKey("DeviceID")) && (this.Parameters["DeviceID"] != null)) ? this.Parameters["DeviceID"].ToString() : "",
                    DeviceName    = ((this.Parameters.ContainsKey("DeviceName")) && (this.Parameters["DeviceName"] != null)) ? this.Parameters["DeviceName"].ToString() : "",
                    OperatorID    = ((this.Parameters.ContainsKey("OperatorID")) && (this.Parameters["OperatorID"] != null)) ? this.Parameters["OperatorID"].ToString() : "",
                    OperatorName  = ((this.Parameters.ContainsKey("OperatorName")) && (this.Parameters["OperatorName"] != null)) ? this.Parameters["OperatorName"].ToString() : "",
                    StationID     = ((this.Parameters.ContainsKey("StationID")) && (this.Parameters["StationID"] != null)) ? this.Parameters["StationID"].ToString() : "",
                    StationName   = ((this.Parameters.ContainsKey("StationName")) && (this.Parameters["StationName"] != null)) ? this.Parameters["StationName"].ToString() : "",
                    LineID        = ((this.Parameters.ContainsKey("LineID")) && (this.Parameters["LineID"] != null)) ? this.Parameters["LineID"].ToString() : "",
                    LineName      = ((this.Parameters.ContainsKey("LineName")) && (this.Parameters["LineName"] != null)) ? this.Parameters["LineName"].ToString() : "",
                    BusinessID    = ((this.Parameters.ContainsKey("BusinessID")) && (this.Parameters["BusinessID"] != null)) ? this.Parameters["BusinessID"].ToString() : "",
                    BusinessName  = ((this.Parameters.ContainsKey("BusinessName")) && (this.Parameters["BusinessName"] != null)) ? this.Parameters["BusinessName"].ToString() : "",
                    OrderID       = ((this.Parameters.ContainsKey("OrderID")) && (this.Parameters["OrderID"] != null)) ? this.Parameters["OrderID"].ToString() : ""
                });

                context.SaveChanges();
            }

            return(pairID.ToString());
        }
コード例 #3
0
        public string SetTransaction(string TransactionID, string SerialNumber, string ProductKeyID)
        {
            long prodcutKeyID = -9;

            if (!long.TryParse(ProductKeyID, out prodcutKeyID))
            {
                throw new FormatException("Invalid value supplied for product key ID!");
            }

            string returnValue = "";

            using (DBModelContainer context = new DBModelContainer())
            {
                ProductKeyIDSerialNumberPairs pair = context.ProductKeyIDSerialNumberPairs.FirstOrDefault((o) => ((o.SerialNumber.ToLower().StartsWith(SerialNumber.ToLower())) && (o.TransactionID.ToLower() == TransactionID.ToLower())));

                //ProductKeyIDSerialNumberPairs pair = context.ProductKeyIDSerialNumberPairs.FirstOrDefault((o) => (o.TransactionID.ToLower() == TransactionID.ToLower()));

                if (pair != null)
                {
                    pair.ProductKeyID     = prodcutKeyID;
                    pair.ModificationTime = DateTime.Now;

                    returnValue = pair.PairID.ToString();

                    context.SaveChanges();
                }
            }

            return(returnValue);
        }
コード例 #4
0
        public string[] Bind(string SerialNumber, string ProductKeyID)
        {
            long prodcutKeyID = -9;

            if (!long.TryParse(ProductKeyID, out prodcutKeyID))
            {
                throw new FormatException("Invalid value supplied for product key ID!");
            }

            string[] returnValue = null;

            List <string> transactionIDs = new List <string>();

            using (DBModelContainer context = new DBModelContainer())
            {
                foreach (var pair in context.ProductKeyIDSerialNumberPairs.Where((o) => (o.SerialNumber.Trim().ToLower() == SerialNumber.ToLower())))
                {
                    if (pair != null)
                    {
                        pair.ProductKeyID     = prodcutKeyID;
                        pair.ModificationTime = DateTime.Now;

                        transactionIDs.Add(pair.TransactionID);
                    }
                }

                returnValue = transactionIDs.ToArray();

                context.SaveChanges();
            }

            return(returnValue);
        }
コード例 #5
0
        /// <summary>
        /// Authenticates the user.
        /// </summary>
        ///<param name="username">Username</param>
        ///<param name="password">Password</param>
        /// <returns>bool</returns>
        public override bool ValidateUser(string username, string password)
        {
            // Lookup user in database, web service, etc. We'll just generate a fake user for this demo.
            DBModelContainer db = new DBModelContainer();

            Models.User userEntity = db.Users
                                     .Include(i => i.Carts)
                                     .Where(i => (i.UserName == username && i.Password == password))
                                     .FirstOrDefault();
            if (userEntity != null)
            {
                // Store the user temporarily in the context for this request.
                FormsAuth.Models.User user = new FormsAuth.Models.User {
                    Id       = userEntity.UserId,
                    Username = userEntity.UserName
                };
                HttpContext.Current.Items.Add("User", user);

                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #6
0
 public void Dispose()
 {
     if (_context != null)
     {
         _context.Dispose();
         _context = null;
     }
 }
コード例 #7
0
        //public ActionResult AddNew([Bind(Include = "OverallRating,Title,Content")] ReviewProduction1 model)
        public async Task <ActionResult> AddNewReview(ReviewProduction model)
        {
            if (UserManager.User != null)
            {
                if (ModelState.IsValid)
                {
                    // save to DB
                    DBModelContainer db = new DBModelContainer();

                    Review review = new Review();
                    review.UserId        = UserManager.User.Id;
                    review.ProductId     = model.ProductId;
                    review.ReviewDate    = DateTime.Now;
                    review.Title         = model.Title;
                    review.Content       = model.Content;
                    review.OverallRating = model.OverallRating;

                    db.Reviews.Add(review);
                    await db.SaveChangesAsync();

                    // Info.

                    /*
                     * return this.Json(new
                     * {
                     *  EnableSuccess = true,
                     *  SuccessTitle = "Success",
                     *  SuccessMsg = "Add new review sucessfully"
                     * });*/

                    List <ReviewProduction> reviewList = (from r in db.Reviews
                                                          join u in db.Users on r.UserId equals u.UserId
                                                          where r.ProductId == model.ProductId
                                                          select new ReviewProduction
                    {
                        ReviewId = r.ReviewId,
                        Title = r.Title,
                        Content = r.Content,
                        OverallRating = r.OverallRating,
                        UserName = u.UserName,
                        ReviewDate = r.ReviewDate,
                    }).ToList();
                    return(PartialView("_PartialPage_ReviewList", reviewList));
                }

                return(this.Json(new
                {
                    ResponseType = Config.SOMETHING_WRONG_WITH_POST_REQUEST,
                    Msg = "Something goes wrong, please try again later"
                }));
            }

            return(this.Json(new
            {
                ResponseType = Config.NEED_LOGIN,
                Msg = "Please login first"
            }));
        }
コード例 #8
0
        public ActionResult ProductDetail(int id)
        {
            DBModelContainer db = new DBModelContainer();
            ProductionDetail pr = new ProductionDetail();

            pr.ProductId = id;

            var names = (from p in db.Products
                         join c in db.Categories on p.CategoryId equals c.CategoryId
                         where p.ProductId == id
                         select new { ProductName = p.Name,
                                      CategoryName = c.Name }).FirstOrDefault();

            pr.Title = names.CategoryName + " > " + names.ProductName;

            pr.listdata = (from p in db.ProductDetails
                           join production in db.Products on p.ProductId equals production.ProductId
                           where p.ProductId == id
                           select new ProductionDetail()
            {
                Color = p.Color,
                Description = production.Description,
                Price = p.Price,
                Size = p.Size,
                Amount = p.Amount,
                Picture = p.Picture,
                ProductDetailsId = p.ProductDetailsId,
                ProductId = p.ProductId,
                ProductionName = production.Name
            }).ToList();

            // return View(productionDetail.FirstOrDefault());
            pr.reviewListData = (from r in db.Reviews
                                 join p in db.Products on r.ProductId equals p.ProductId
                                 join u in db.Users on r.UserId equals u.UserId
                                 where p.ProductId == id
                                 select new ReviewProduction()
            {
                ProductId = r.ProductId,

                Title = r.Title,
                Content = r.Content,
                OverallRating = r.OverallRating,

                ReviewId = r.ReviewId,
                UserId = r.UserId,
                UserName = u.UserName,
                ReviewDate = r.ReviewDate
            }).ToList();

            return(View(pr));
        }
コード例 #9
0
        // GET: MySearch
        public ActionResult Index()
        {
            DBModelContainer db = new DBModelContainer();

            var categories = from c in db.Categories
                             select c;

            categories = categories.OrderBy(c => c.CategoryId).Take(20);

            ViewBag.categories = categories;

            return(PartialView());
        }
コード例 #10
0
        public ProductKeyIDSerialNumberPairs[] GetTransactionsByOrder(string OrderID)
        {
            ProductKeyIDSerialNumberPairs[] returnValue = null;

            using (DBModelContainer context = new DBModelContainer())
            {
                var rawPairs = context.ProductKeyIDSerialNumberPairs.Where((o) => (o.OrderID.ToLower() == OrderID.ToLower()));

                if (rawPairs != null)
                {
                    returnValue = rawPairs.OrderBy((p) => (p.CreationTime)).ToArray();
                }
            }

            return(returnValue);
        }
コード例 #11
0
        public string AddTransaction(ProductKeyIDSerialNumberPairs Transaction)
        {
            string returnValue = "";

            using (DBModelContainer context = new DBModelContainer())
            {
                Transaction.CreationTime = DateTime.Now;

                var result = context.ProductKeyIDSerialNumberPairs.Add(Transaction);

                context.SaveChanges();

                returnValue = result.TransactionID;
            }

            return(returnValue);
        }
コード例 #12
0
        public async Task <ActionResult> Index(int categoryId, int?page)
        {
            DBModelContainer  db      = new DBModelContainer();
            ProductionService service = new ProductionService();

            // get all products of a given category
            List <Production> prs = await service.getProductsByCategoryId(categoryId);

            if (prs != null && prs.Count > 0)
            {
                int pageSize   = 16;
                int pageNumber = (page ?? 1);

                return(View(prs.ToPagedList(pageNumber, pageSize)));
            }

            return(RedirectToAction("Index", "Category"));
        }
コード例 #13
0
        // GET: Category
        public ActionResult Index(int?page)
        {
            DBModelContainer db = new DBModelContainer();
            //IQueryable<Category> categories = db.Category
            //                    .OrderBy(c => c.CategoryId);
            //.Skip(8 * (page - 1))
            //.Take(8);

            var categories = from c in db.Categories
                             select c;

            categories = categories.OrderBy(c => c.CategoryId);

            int pageSize   = 8;
            int pageNumber = (page ?? 1);

            //return View(categories.ToList());
            return(View(categories.ToPagedList(pageNumber, pageSize)));
        }
コード例 #14
0
        public async Task <ActionResult> ProductDetail(int id)
        {
            DBModelContainer db = new DBModelContainer();
            ProductionDetail pr = new ProductionDetail();

            pr.ProductId = id;

            // get product title equal to CategoryName + " > " + names.ProductName;
            ProductionService service = new ProductionService();

            pr.Title = (await service.getProductTitleByProductId(id)).Title;

            /*{
             *  Color,
             *  Description,
             *  Price,
             *  Size,
             *  Amount,
             *  Picture,
             *  ProductDetailsId,
             *  ProductId,
             *  ProductionName
             * }*/
            // get all productDetails by a given product
            pr.listdata = await service.getProductDetailsByProductId(id);

            /*{
             *  ProductId,
             *
             *  Title,
             *  Content,
             *  OverallRating,
             *
             *  ReviewId,
             *  UserId,
             *  UserName,
             *  ReviewDate
             * }*/
            // get all reviews about a given product
            pr.reviewListData = await service.getReviewsByProductId(id);

            return(View(pr));
        }
コード例 #15
0
        public ProductKeyIDSerialNumberPairs[] GetTransactionsByDateRange(string StartTimeUTC, string EndTimeUTC)
        {
            DateTime startTime = DateTime.Parse(StartTimeUTC);

            DateTime endTime = DateTime.Parse(EndTimeUTC);

            ProductKeyIDSerialNumberPairs[] returnValue = null;

            using (DBModelContainer context = new DBModelContainer())
            {
                var rawPairs = context.ProductKeyIDSerialNumberPairs.Where((o) => ((o.CreationTime >= startTime) && (o.CreationTime <= endTime)));

                if (rawPairs != null)
                {
                    returnValue = rawPairs.OrderBy((p) => (p.CreationTime)).ToArray();
                }
            }

            return(returnValue);
        }
コード例 #16
0
        public ProductKeyIDSerialNumberPairs GetTransaction()
        {
            ProductKeyIDSerialNumberPairs returnValue = null;

            using (DBModelContainer context = new DBModelContainer())
            {
                var rawPairs = context.ProductKeyIDSerialNumberPairs.Where((o) => (o.ProductKeyID == null));

                if (rawPairs != null)
                {
                    ProductKeyIDSerialNumberPairs[] pairs = rawPairs.OrderBy((p) => (p.CreationTime)).ToArray();

                    if ((pairs != null) && (pairs.Length > 0))
                    {
                        returnValue = pairs[0];
                    }
                }
            }

            return(returnValue);
        }
コード例 #17
0
        public ActionResult CartIcon()
        {
            int cartItemNumber = 0;

            if (FormsAuth.UserManager.User != null)
            {
                DBModelContainer db           = new DBModelContainer();
                List <CartItem>  cartItemList = (from c in db.Carts
                                                 join cd in db.CartDetails on c.CartId equals cd.CartId
                                                 where c.UserId == UserManager.User.Id
                                                 select new CartItem
                {
                    ProductDetailsId = cd.ProductDetailsId,
                    Price = cd.ExtendedPrice,
                    Amount = cd.Amount
                }).ToList();

                cartItemNumber = cartItemList.Count();
            }
            else
            {
                HttpCookie reqIDListCookies = Request.Cookies["ProductDetailIDlist"];
                if (reqIDListCookies != null)
                {
                    string dataAsString = reqIDListCookies.Value;
                    if (!dataAsString.Equals(string.Empty))
                    {
                        List <int> listdata = new List <int>();
                        listdata = dataAsString.Split(',').Select(x => Convert.ToInt32(x)).ToList();

                        cartItemNumber = listdata.Count();
                    }
                }
            }

            ViewBag.cartItemNumber = cartItemNumber;
            return(PartialView());
        }
コード例 #18
0
        //Обработка нового файла
        private void ProcessDataFile(object parameters)
        {
            if (parameters is string)
            {
                string           fileName  = parameters as string;
                Parser           parser    = new Parser();
                DBModelContainer container = new DBModelContainer();

                if (container.CheckFileName(fileName) == false)
                {
                    try
                    {
                        container.AddOrders(parser.ParseList(fileName));
                        container.AddFileName(fileName);
                        Console.WriteLine("Файл " + fileName + " обработан");
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                }
            }
        }
コード例 #19
0
    protected void LinkButtonExportSelected_Click(object sender, EventArgs e)
    {
        CheckBox checkBoxSelect = null;

        List <string> selectedDataKeys = new List <string>();

        ProductKeyIDSerialNumberPairs[] pairs = null;

        string script = "window.alert('No available data to export!')";

        foreach (GridViewRow row in this.GridView1.Rows)
        {
            checkBoxSelect = row.Cells[0].FindControl("CheckBoxSelectItem") as CheckBox;

            if ((checkBoxSelect != null) && (checkBoxSelect.Checked))
            {
                //selectedDataKeys.Add(this.GridView1.DataKeys[row.DataItemIndex].Values[0].ToString());

                foreach (Control control in row.Cells[1].Controls)
                {
                    if (control is DynamicHyperLink)
                    {
                        selectedDataKeys.Add((control as DynamicHyperLink).Text.ToLower());

                        break;
                    }
                }

                //selectedDataKeys.Add((row.Cells[1].Controls[1] as DynamicHyperLink).Text);
            }
        }

        if ((selectedDataKeys != null) && (selectedDataKeys.Count > 0))
        {
            try
            {
                using (DBModelContainer context = new DBModelContainer())
                {
                    pairs = context.ProductKeyIDSerialNumberPairs.Where((o) => (selectedDataKeys.Contains(o.TransactionID.ToLower()))).ToArray();
                }

                XmlUtility xmlUtil = new XmlUtility();

                string pairXml = xmlUtil.XmlSerialize(pairs, null, "utf-8");

                if (!String.IsNullOrEmpty(pairXml))
                {
                    pairXml = XmlUtility.XmlTransform(pairXml, Server.MapPath("~/XSLT/Transform-ProductKeyIDSerialNumberPairs-Excel2003.xslt"), "utf-8");

                    byte[] fileBytes = System.Text.Encoding.UTF8.GetBytes(pairXml);

                    Context.Response.ContentType = "application/x-msdownload";

                    Context.Response.AppendHeader("Content-Disposition", String.Format("attachment;filename=DPK-SN-Bundle-Export-{0}.xml", DateTime.Now.ToString("yyyy-MM-ddThh-mm-ss-fff")));

                    Context.Response.OutputStream.Write(fileBytes, 0, fileBytes.Length);

                    Context.Response.Flush();

                    Context.Response.End();
                }
            }
            catch (Exception ex)
            {
                MES.Utility.TracingUtility.Trace(new object[] { "Export Failed!", ex, String.Format("Time: {0}", DateTime.Now) }, null);
                script = "window.alert('Export Failed!')";
                this.Page.ClientScript.RegisterClientScriptBlock(this.Page.GetType(), Guid.NewGuid().ToString(), script, true);
                return;
            }
        }
        else
        {
            this.Page.ClientScript.RegisterClientScriptBlock(this.Page.GetType(), Guid.NewGuid().ToString(), script, true);
            return;
        }
    }
コード例 #20
0
 public ProductRepository(DBModelContainer context)
 {
     _context = context;
 }
コード例 #21
0
 public SaleInfoRepository(DBModelContainer context)
 {
     _context = context;
 }
コード例 #22
0
 public TagsRepository(DBModelContainer context) : base(context)
 {
 }
コード例 #23
0
ファイル: UnitOfWork.cs プロジェクト: stefanbotez/Proiect2
 public UnitOfWork()
 {
     _context = new DBModelContainer();
     Media    = new MediaRepository(_context);
     Tags     = new TagsRepository(_context);
 }
コード例 #24
0
 public EFUnitOfWork()
 {
     _context = new DBModelContainer();
 }
コード例 #25
0
        public ActionResult ReviewProduction(int id)
        {
            DBModelContainer db            = new DBModelContainer();
            ReviewDetails    reviewDetails = new ReviewDetails();

            Production production = (from p in db.Products
                                     join pDetail in db.ProductDetails on p.ProductId equals pDetail.ProductId
                                     where p.ProductId == id
                                     select new
            {
                p.ProductId,
                p.Name,
                pDetail.Price,
                pDetail.Picture,
                pDetail.Color
            } into t1
                                     group t1 by t1.ProductId into g
                                     select new Production
            {
                ProductId = g.Key,
                ProductionName = g.FirstOrDefault().Name,
                MinPrice = g.Min(m => m.Price),
                MaxPrice = g.Max(m => m.Price),
                Picture = g.FirstOrDefault().Picture,
                Color = g.FirstOrDefault().Color
            }).FirstOrDefault();

            reviewDetails.product = production;

            List <ReviewProduction> reviewList = (from r in db.Reviews
                                                  join u in db.Users on r.UserId equals u.UserId
                                                  where r.ProductId == id
                                                  select new ReviewProduction
            {
                ReviewId = r.ReviewId,
                Title = r.Title,
                Content = r.Content,
                OverallRating = r.OverallRating,
                UserName = u.UserName,
                ReviewDate = r.ReviewDate,
            }).ToList();

            reviewDetails.reviewList = reviewList;

            var reviewNumbers = (from r in reviewList
                                 group r by new { r.OverallRating } into g
                                 select new
            {
                OverrallRating = g.Key.OverallRating,
                Count = g.Count()
            }).ToList();

            Rating rating = new Rating();

            // calculate number and percent of each rate
            foreach (var reviewNumber in reviewNumbers)
            {
                if (reviewNumber.OverrallRating == 1)
                {
                    rating.oneStarReviewNumber = reviewNumber.Count;
                }
                else if (reviewNumber.OverrallRating == 2)
                {
                    rating.twoStarReviewNumber = reviewNumber.Count;
                }
                else if (reviewNumber.OverrallRating == 3)
                {
                    rating.threeStarReviewNumber = reviewNumber.Count;
                }
                else if (reviewNumber.OverrallRating == 4)
                {
                    rating.fourStarReviewNumber = reviewNumber.Count;
                }
                else if (reviewNumber.OverrallRating == 5)
                {
                    rating.fiveStarReviewNumber = reviewNumber.Count;
                }
            }
            rating.oneStarReviewPercent   = Convert.ToDecimal(String.Format("{0:0.0000}", rating.oneStarReviewNumber * 100 / reviewList.Count()));
            rating.twoStarReviewPercent   = Convert.ToDecimal(String.Format("{0:0.0000}", rating.twoStarReviewNumber * 100 / reviewList.Count()));
            rating.threeStarReviewPercent = Convert.ToDecimal(String.Format("{0:0.0000}", rating.threeStarReviewNumber * 100 / reviewList.Count()));
            rating.fourStarReviewPercent  = Convert.ToDecimal(String.Format("{0:0.0000}", rating.fourStarReviewNumber * 100 / reviewList.Count()));
            rating.fiveStarReviewPercent  = Convert.ToDecimal(String.Format("{0:0.0000}", rating.fiveStarReviewNumber * 100 / reviewList.Count()));

            // calculate average overral rating
            decimal overrall = 0;

            foreach (ReviewProduction review in reviewList)
            {
                overrall += review.OverallRating;
            }
            overrall = overrall / reviewList.Count();
            overrall = Convert.ToDecimal(String.Format("{0:0.0}", overrall));
            rating.overrallRating = overrall;

            reviewDetails.rating = rating;

            // render View
            return(View(reviewDetails));
        }
コード例 #26
0
        public ActionResult Index(SearchModel model)
        {
            DBModelContainer db = new DBModelContainer();

            string searchText = model.Criteria;

            string[] searchArr = new string[] { " " };
            if (searchText != null && !searchText.Trim().Equals("")) //search all
            {
                searchText = searchText.ToLower().Trim();
                searchArr  = searchText.Split(' ');
            }

            List <SearchProduction> searchProductionList = (from p in db.Products
                                                            join category in db.Categories on p.CategoryId equals category.CategoryId
                                                            join pdetail in db.ProductDetails on p.ProductId equals pdetail.ProductId
                                                            where searchArr.Any(w => p.Description.ToLower().Contains(w) || p.Name.ToLower().Contains(w) ||
                                                                                category.Name.ToLower().Contains(w) || category.Description.ToLower().Contains(w))
                                                            select new
            {
                ProductId = p.ProductId,
                Name = p.Name,
                Description = p.Description,
                Picture = pdetail.Picture,
                Color = pdetail.Color,
                Price = pdetail.Price,
                CategoryId = category.CategoryId,
                CategoryName = category.Name,
                CategoryDescription = category.Description
            } into t1
                                                            group t1 by t1.ProductId into g
                                                            select new SearchProduction()
            {
                ProductId = g.FirstOrDefault().ProductId,
                Name = g.FirstOrDefault().Name,
                Description = g.FirstOrDefault().Description,
                Picture = g.FirstOrDefault().Picture,
                Color = g.FirstOrDefault().Color,
                Price = g.FirstOrDefault().Price,
                CategoryId = g.FirstOrDefault().CategoryId,
                CategoryName = g.FirstOrDefault().CategoryName,
                CategoryDescription = g.FirstOrDefault().CategoryDescription
            }).ToList();

            if (model.CategoryId != 0)
            {
                searchProductionList = (from s in searchProductionList
                                        where s.CategoryId == model.CategoryId
                                        select new SearchProduction()
                {
                    ProductId = s.ProductId,
                    Name = s.Name,
                    Description = s.Description,
                    Picture = s.Picture,
                    Color = s.Color,
                    Price = s.Price,
                    CategoryId = s.CategoryId,
                    CategoryName = s.CategoryName,
                    CategoryDescription = s.CategoryDescription
                }).ToList();
            }

            // Use Left Join ( products that haven't received any review are also listed out )
            searchProductionList = (from p in searchProductionList
                                    join r in db.Reviews on p.ProductId equals r.ProductId
                                    into tmp
                                    from t in tmp.DefaultIfEmpty()
                                    select new
            {
                p.ProductId,
                p.Name,
                p.Description,
                p.Picture,
                p.Color,
                p.Price,
                p.CategoryName,
                p.CategoryDescription,
                OverallRating = (t?.OverallRating ?? 0),
            } into t1
                                    group t1 by t1.ProductId into g
                                    select new SearchProduction()
            {
                ProductId = g.FirstOrDefault().ProductId,
                Name = g.FirstOrDefault().Name,
                Description = g.FirstOrDefault().Description,
                Picture = g.FirstOrDefault().Picture,
                Color = g.FirstOrDefault().Color,
                Price = g.FirstOrDefault().Price,
                CategoryName = g.FirstOrDefault().CategoryName,
                CategoryDescription = g.FirstOrDefault().CategoryDescription,
                OverallRating = ((decimal)g.Sum(item => item.OverallRating)) / g.Count(),
                Count = ((short)(g.Sum(item => item.OverallRating) / g.Count())) == 0 ? 0 : g.Count()
            }).ToList();
            int pageSize   = 16;
            int pageNumber = 1;

            return(PartialView("Index", searchProductionList.ToPagedList(pageNumber, pageSize)));

            #region Not Used

            /*
             * System.Collections.Generic.List<SearchProduction> searchProductionList = (from p in db.Products
             *                                 join category in db.Categories on p.CategoryId equals category.CategoryId
             *                                 join pdetail in db.ProductDetails on p.ProductId equals pdetail.ProductId
             *                                 where searchArr.Any(w => p.Description.ToLower().Contains(w) || p.Name.ToLower().Contains(w) || category.Name.ToLower().Contains(w) || category.Description.ToLower().Contains(w))
             *                                 select new
             *                                 {
             *                                     Name = p.Name,
             *                                     Description = p.Description,
             *                                     CategoryName = category.Name,
             *                                     ProductId = p.ProductId,
             *                                     Picture = pdetail.Picture,
             *                                     Color = pdetail.Color,
             *                                     Price = pdetail.Price,
             *                                     CategoryDescription = category.Description
             *                                 } into t1
             *                                 group t1 by t1.ProductId into g
             *                                 select new SearchProduction()
             *                                 {
             *                                     Name = g.FirstOrDefault().Name,
             *                                     Description = g.FirstOrDefault().Description,
             *                                     CategoryName = g.FirstOrDefault().CategoryName,
             *                                     ProductId = g.FirstOrDefault().ProductId,
             *                                     Picture = g.FirstOrDefault().Picture,
             *                                     Color = g.FirstOrDefault().Color,
             *                                     Price = g.FirstOrDefault().Price,
             *                                     CategoryDescription = g.FirstOrDefault().CategoryDescription
             *                                 } ).ToList<SearchProduction>();
             */
            /* searchList.searchProductionList = (from p in db.Products
             *                                 join category in db.Categories on p.CategoryId equals category.CategoryId
             *                                 join pdetail in db.ProductDetails on p.ProductId equals pdetail.ProductId
             *                                 //where (p.Name.Contains(searchText) || p.Description.Contains(searchText) || category.Name.Contains(searchText) || category.Description.Contains(searchText))
             *                                 // where (searchArr.Contains(p.Name) || searchArr.Contains(p.Description) || searchArr.Contains(category.Name) || searchArr.Contains(category.Description))
             *
             *                                 //         where (from item in searchArr
             *                                 //               select item).Contains(p.Description.ToLower())//, p.Description)
             *                                 where searchArr.Any(w => p.Description.ToLower().Contains(w) || p.Name.ToLower().Contains(w) || category.Name.ToLower().Contains(w) || category.Description.ToLower().Contains(w))
             *                                 select new
             *                                 {
             *                                     Name = p.Name,
             *                                     Description = p.Description,
             *                                     CategoryName = category.Name,
             *                                     ProductId = p.ProductId,
             *                                     Picture = pdetail.Picture,
             *                                     Color = pdetail.Color,
             *                                     Price = pdetail.Price,
             *                                     CategoryDescription = category.Description
             *                                 } into t1
             *                                 group t1 by t1.ProductId into g
             *                                 select new SearchProduction()
             *                                 {
             *                                     Name = g.FirstOrDefault().Name,
             *                                     Description = g.FirstOrDefault().Description,
             *                                     CategoryName = g.FirstOrDefault().CategoryName,
             *                                     ProductId = g.FirstOrDefault().ProductId,
             *                                     Picture = g.FirstOrDefault().Picture,
             *                                     Color = g.FirstOrDefault().Color,
             *                                     Price = g.FirstOrDefault().Price,
             *                                     CategoryDescription = g.FirstOrDefault().CategoryDescription
             *                                 } into pp
             *                                 join review in (from re in db.Reviews
             *                                                 group re by re.ProductId into g
             *                                                 select new ReviewProduction()
             *                                                 {
             *                                                     ProductId = g.Key,
             *                                                     OverallRating = (short)(g.Sum(item => item.OverallRating) / g.Count()),
             *                                                     Count = g.Count()
             *                                                 }).ToList()
             *                                                 on pp.ProductId equals review.ProductId
             *                                                 into gj
             *                                  from subpet in gj.DefaultIfEmpty()
             *
             *                                  select new SearchProduction()
             *                                 {
             *                                     Name = pp.Name,
             *                                     Description = pp.Description,
             *                                     CategoryName = pp.Name,
             *                                     ProductId = pp.ProductId,
             *                                     Picture =  pp.Picture,
             *                                     Color =  pp.Color,
             *                                     Price = pp.Price,
             *                                     CategoryDescription = pp.CategoryDescription,
             *                                     OverallRating = 0,
             *                                     Count = 0
             *                                  }).ToList();
             *
             * var ReviewList = (from re in db.Reviews
             *                group re by re.ProductId into g
             *                select new ReviewProduction()
             *                {
             *                    ProductId = g.Key,
             *                    OverallRating = (short)(g.Sum(item => item.OverallRating) / g.Count()),
             *                    Count = g.Count()
             *                }).ToList();  */
            /*  var s = searchList.searchProductionList.SelectMany
             * (
             *   p => ReviewList.Where(re => p.ProductId == re.ProductId).DefaultIfEmpty(),
             *   (p, re) => new
             *   {
             *       p, re
             *   }
             * ).ToList().Select(x => new SearchProduction()
             * {
             *   Name = x.p.Name,
             *   Description = x.p.Description,
             *   CategoryName = x.p.Name,
             *   ProductId = x.p.ProductId,
             *   Picture = x.p.Picture,
             *   Color = x.p.Color,
             *   Price = x.p.Price,
             *   CategoryDescription = x.p.CategoryDescription,
             *   OverallRating = x.re.OverallRating,
             *   Count = x.re.Count
             * }).ToList(); ;
             *
             * var s = searchProductionList.GroupJoin(ReviewList,
             *       p => p.ProductId,
             *       re => re.ProductId,
             *
             *       (p, tmp) => new { tmp, p }).ToList().Select(x => new SearchProduction()
             *       {
             *           Name = x.p.Name,
             *           Description = x.p.Description,
             *           CategoryName = x.p.Name,
             *           ProductId = x.p.ProductId,
             *           Picture = x.p.Picture,
             *           Color = x.p.Color,
             *           Price = x.p.Price,
             *           CategoryDescription = x.p.CategoryDescription,
             *           OverallRating = x.tmp.Where(a => a.ProductId!=0).FirstOrDefault()?.OverallRating??0,
             *           Count = x.tmp.Where(a => a.ProductId != 0).FirstOrDefault()?.Count ?? 0,
             *       }).ToList();
             *
             * //    searchList.searchProductionList = searchList.searchProductionList.GroupBy(c => c.ProductId);
             *
             * // var s =  searchList.searchProductionList.Where(t => searchArr.Any(w => t.Description.ToLower().Contains(w)|| t.Name.ToLower().Contains(w) || t.CategoryName.ToLower().Contains(w) || t.CategoryName.ToLower().Contains(w))).ToList() ;
             * searchProductionList = s;
             */
            #endregion
        }
コード例 #27
0
 public ManagerRepository(DBModelContainer context)
 {
     _context = context;
 }
コード例 #28
0
 public MediaRepository(DBModelContainer context) : base(context)
 {
 }
コード例 #29
0
        public object Save(DataPair DataPair)
        {
            DBDataIdentifier identifier = new DBDataIdentifier()
            {
                DataUniqueID = DataPair.Identifier.DataUniqueID,
                DataType     = ((DBDataType)(DataPair.Identifier.DataType)),
                RawData      = DataPair.Identifier.RawData as byte[]
            };

            DBDataItem dataItem;

            List <DBDataItem> dataItems = new List <DBDataItem>();

            List <string> dataItemIDList = null;

            for (int i = 0; i < DataPair.Items.Count; i++)
            {
                dataItem = new DBDataItem()
                {
                    DataItemID     = Guid.NewGuid().ToString(),
                    DataIdentifier = identifier,
                    DataUniqueID   = DataPair.Identifier.DataUniqueID,
                    CreationTime   = DataPair.Items[i].CreationTime,
                    DataBytes      = DataPair.Items[i].DataBytes,
                    Description    = DataPair.Items[i].Description,
                    DeviceID       = DataPair.Items[i].DeviceID,
                    LocationID     = DataPair.Items[i].LocationID,
                    Size           = DataPair.Items[i].Size
                };

                List <DBDataParameter> dataParameters = new List <DBDataParameter>();


                if (DataPair.Items[i].DataParameters != null)
                {
                    for (int j = 0; j < DataPair.Items[i].DataParameters.Count; j++)
                    {
                        dataParameters.Add(new DBDataParameter()
                        {
                            ID         = Guid.NewGuid().ToString(),
                            Name       = DataPair.Items[i].DataParameters[j].Name,
                            Value      = DataPair.Items[i].DataParameters[j].Value,
                            DataItem   = dataItem,
                            DataItemID = dataItem.DataItemID
                        });
                    }
                }

                dataItem.DataParameters = dataParameters.ToArray();
                dataItems.Add(dataItem);
            }

            identifier.DataItems = dataItems.ToArray();

            using (DBModelContainer context = new DBModelContainer())
            {
                var dbident = context.DBDataIdentifiers.FirstOrDefault((o) => (o.DataUniqueID.ToLower() == identifier.DataUniqueID.ToLower()));

                if (dbident != null)
                {
                    foreach (var item in identifier.DataItems)
                    {
                        //dbident.DataItems.Add(item);
                        item.DataIdentifier = dbident;
                        context.DBDataItems.Add(item);
                    }

                    //identifier = dbident;
                }
                else
                {
                    identifier = context.DBDataIdentifiers.Add(identifier);
                }

                context.SaveChanges();
            }

            if (identifier != null)
            {
                dataItemIDList = new List <string>();

                foreach (var item in identifier.DataItems)
                {
                    dataItemIDList.Add(item.DataItemID);
                }
            }

            return(dataItemIDList);
        }
コード例 #30
0
 public Repository(DBModelContainer context)
 {
     _context = context;
     dbSet    = _context.Set <T>();
 }