public IEnumerable <Product> MostDownload()
        {
            List <Product> Products     = new Biz.ProductBiz().GetAll();
            var            Downloads    = new Biz.DownloadBiz().GetAll();
            var            mostDownload = (from t in Downloads
                                           group t by t.Product.Id
                                           into g
                                           select new
            {
                ProductId = g.Key,
                Count = g.Count()
            }).OrderByDescending(x => x.Count)
                                          .Select(x => x.ProductId)
                                          .Take(20)
                                          .ToList();

            return(Biz.ApiMapper.Map(Products.Where(x => mostDownload.Contains(x.Id)).ToList()));
        }
        public ActionResult Download(int productId)
        {
            OperationResult result = new Biz.DownloadBiz().Create(new UserDownload()
            {
                Product_Id = productId
            });

            if (result.Succeed)
            {
                string path     = AppDomain.CurrentDomain.BaseDirectory + "Content\\Downloads\\";
                string fileName = new Biz.ProductBiz().GetAll().Where(x => x.Id == productId).Select(x => x.FileUpload).FirstOrDefault();
                //TODO : Name File Download
                byte[] fileBytes = System.IO.File.ReadAllBytes(path + fileName);
                return(File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, fileName));
            }
            return(File(new byte[0] {
            }, System.Net.Mime.MediaTypeNames.Application.Octet, "notFound.txt"));
        }
Exemple #3
0
        public ActionResult Get(int id)
        {
            ShowProductDetiels result = new ShowProductDetiels();

            var product = new Biz.ProductBiz().Get(id);

            result.Product = product;
            double Rate      = product.Rate;
            int    downloads = new Biz.DownloadBiz().GetDownloadCount(id);
            int    comments  = new Biz.CommentBiz().CommnetsCount(id);

            result.Comments = new Biz.CommentBiz().Get(id).OrderByDescending(x => x.DateTime).ToList();
            result.Counts   = new CountsViewModel()
            {
                CommentsCount = comments, DownloadsCount = downloads, RateCounts = Rate
            };

            return(View("SmallProduct", result));
        }
Exemple #4
0
        public ActionResult Create(Product p)
        {
            if (Request.Files.Count > 0)
            {
                p.ProductImages = new List <ProductImage>();
                string pathImage    = Server.MapPath("~/Content/images/iconProduct/");
                string pathFile     = Server.MapPath("~/Content/Downloads/");
                int    counterIamge = 0;
                int    counterFile  = 0;

                foreach (HttpPostedFileBase file in Request.Files.GetMultiple("FileUpload"))
                {
                    file.SaveAs(pathFile + file.FileName);
                    p.FileUpload = file.FileName;
                    p.FileSize   = getFileSize(file.InputStream.Length);
                    counterFile++;
                }

                foreach (HttpPostedFileBase file in Request.Files.GetMultiple("Logo"))
                {
                    string fileName = Guid.NewGuid() + Path.GetExtension(file.FileName);
                    file.SaveAs(pathImage + fileName);

                    p.ProductImages.Add(new ProductImage()
                    {
                        ImageName = fileName,
                        Type      = counterIamge == p.LogoIndex ? ImageType.Logo : ImageType.Details
                    });

                    counterIamge++;
                }
            }

            var result = new Biz.ProductBiz().Create(p);

            if (result.Succeed)
            {
                return(RedirectToAction("Manage"));
            }
            return(View(p));
        }
Exemple #5
0
        // POST api/<controller>
        public OperationResult Post([FromBody] Comment model)
        {
            var OperationResult = new Biz.CommentBiz().Create(new Comment()
            {
                Description = model.Description, Product_Id = model.Product_Id, UserRate = model.UserRate
            });

            if (!OperationResult.Succeed)
            {
                return(OperationResult);
            }
            else
            {
                double rate = new Biz.CommentBiz().GetRate(model.Product_Id);

                Product product = new Biz.ProductBiz().Get(model.Product_Id);

                product.Rate = rate;
                return(new Biz.ProductBiz().Edit(product));
            }
        }
Exemple #6
0
        public ActionResult Index()
        {
            List <Product> Products = new Biz.ProductBiz().GetAll();



            var GameApps = new Biz.GroupBiz().GetAll().Where(x => x.Type == AppStore.Models.TypeGroup.Game).SelectMany(p => p.Products).ToList();



            var NewApps = Products.OrderByDescending(x => x.DateTime).Take(20).ToList();


            HomeProducts result = new HomeProducts()
            {
                Games   = GameApps,
                NewApps = NewApps,
            };

            var Downloads    = new Biz.DownloadBiz().GetAll();
            var mostDownload = (from t in Downloads
                                group t by t.Product.Id
                                into g
                                select new
            {
                ProductId = g.Key,
                Count = g.Count()
            }).OrderByDescending(x => x.Count)
                               .Select(x => x.ProductId)
                               .Take(20)
                               .ToList();

            result.MostDownloaded = Products.Where(x => mostDownload.Contains(x.Id)).ToList();


            return(View(result));
        }
Exemple #7
0
        public ActionResult Create(string description, int productId, int Rate)
        {
            var OperationResult = new Biz.CommentBiz().Create(new Comment()
            {
                Description = description, Product_Id = productId, UserRate = Rate
            });

            if (!OperationResult.Succeed)
            {
                //  Send "false"
                return(Json(new { success = false, responseText = OperationResult.Message }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                double rate = new Biz.CommentBiz().GetRate(productId);

                Product product = new Biz.ProductBiz().Get(productId);

                product.Rate = rate;
                new Biz.ProductBiz().Edit(product);
                //  Send "Success"
                return(Json(new { success = true }, JsonRequestBehavior.AllowGet));
            }
        }
        // POST api/<controller>
        public OperationResult Post([FromBody] Product model)
        {
            var result = new Biz.ProductBiz().Create(model);

            return(result);
        }
        // GET api/<controller>/5
        public Product Get(int id)
        {
            var product = new Biz.ProductBiz().Get(id);

            return(Biz.ApiMapper.Map(product));
        }
Exemple #10
0
        public ActionResult Search(string strSearch)
        {
            var list = new Biz.ProductBiz().Find(strSearch);

            return(View("list", list));
        }