Esempio n. 1
0
 static async Task MainAsync()
 {
     ProductClient pc = new ProductClient();
     var product = await pc.GetAsync(1);
     Console.WriteLine(product.Name);
     Console.ReadKey();
 }
Esempio n. 2
0
        // GET: Product
        public ActionResult Index()
        {
            ProductClient CC = new ProductClient();

            ViewBag.listProducts = CC.findAll();

            return(View());
        }
Esempio n. 3
0
        public ActionResult Edit(int id)
        {
            ProductClient    pc  = new ProductClient();
            ProductViewModel pvm = new ProductViewModel();

            // pvm.product = pc.find(id);
            return(View("Index", pvm));
        }
        public ActionResult RelatedProduct(int typeid)
        {
            ProductClient CC = new ProductClient();

            //can san pham cung loai
            ViewBag.ProductsByType = CC.findbyType(typeid).OrderByDescending(x => x.Name);
            return(View());
        }
Esempio n. 5
0
        public async Task <IList <Candle> > GetDailyRates(Coin coin, int days)
        {
            var client    = new ProductClient(EnvironmentVariables.ApiBaseUri, _authenticator);
            var productId = $"{coin.ToUpperString()}-EUR";

            return(await client.GetHistoricRatesAsync(productId, DateTimeOffset.UtcNow.AddDays(-1 * (days + 1)),
                                                      DateTimeOffset.UtcNow, TimeSpan.FromDays(1)));
        }
Esempio n. 6
0
        public ActionResult Create(ProductViewModel pvm)
        {
            pvm.product.CreationDate = DateTime.Now;
            ProductClient pc = new ProductClient();

            pc.Create(pvm.product);
            return(RedirectToAction("Index"));
        }
Esempio n. 7
0
        public ActionResult Edit(int id)
        {
            ProductClient    pc        = new ProductClient();
            ProductViewModel productVM = new ProductViewModel();

            //productVM.Product = pc. TO DO
            return(RedirectToAction("Edit", productVM));
        }
Esempio n. 8
0
 /// <summary>
 /// 修改产品
 /// </summary>
 /// <param name="info"></param>
 /// <param name="operatorName"></param>
 /// <param name="channel"></param>
 /// <returns></returns>
 public static string CreateProductV2(WholeProductInfo info, string operatorName, ChannelType channel)
 {
     using (var client = new ProductClient())
     {
         var serviceResult = client.CreateProductV2(info, operatorName, channel);
         serviceResult.ThrowIfException(true);
         return(serviceResult.Result);
     }
 }
Esempio n. 9
0
 public static Dictionary <string, string> GetProductsModel(List <string> pids)
 {
     using (var client = new ProductClient())
     {
         var result = client.SelectCategoryNameAllLeversByPidsAsync(pids);
         result.Result.ThrowIfException();
         return(result.Result.Result);
     }
 }
Esempio n. 10
0
        public AddOrder()
        {
            InitializeComponent();

            accountService = new AccountClient();
            orderService = new OrderClient();
            productService = new ProductClient();
            detail = new List<DetailOrder>();
        }
Esempio n. 11
0
        public ActionResult Edit()
        {
            ProductViewModel pvm = new ProductViewModel();

            ProductClient pc = new ProductClient();

            pc.Edit(pvm.Product);
            return(RedirectToAction("Index"));
        }
Esempio n. 12
0
        public AddOrder()
        {
            InitializeComponent();

            accountService = new AccountClient();
            orderService   = new OrderClient();
            productService = new ProductClient();
            detail         = new List <DetailOrder>();
        }
Esempio n. 13
0
 private void threadInit_DoWork(object sender, DoWorkEventArgs e)
 {
     sv       = new ProductClient();
     svCat    = new CategoryClient();
     products = sv.findAll();
     threadInit.ReportProgress(60);
     categories = svCat.findAll();
     threadInit.ReportProgress(100);
 }
        public string Get(int left, int right)
        {
            // Call out to multiplying service.
            var productClient = new ProductClient(new RestProxy(), ProductClientUri);
            var product       = productClient.GetMultiplication(left, right).Result;

            // Square result.
            return((product.Total * product.Total).ToString());
        }
Esempio n. 15
0
        public async Task <GeneratedService.ProductJson> GetProductAsync(
            [Service] ITopicEventSender eventSender, [Service] ProductClient service, CancellationToken cancellationToken, int id)
        {
            ProductJson product = await service.GetFullProductsByIdAsync(id, cancellationToken);

            await eventSender.SendAsync(nameof(SubscriptionObjectType.SubscribeProductGetDate), product, cancellationToken);

            return(product);
        }
Esempio n. 16
0
 public void frmProductInit()
 {
     sv         = new ProductClient();
     svCat      = new CategoryClient();
     products   = sv.findAll();
     categories = svCat.findAll();
     initComboBox();
     showProduct(0);
     bindData(products);
 }
Esempio n. 17
0
 public void frmProductInit()
 {
     sv = new ProductClient();
     svCat = new CategoryClient();
     products = sv.findAll();
     categories = svCat.findAll();
     initComboBox();
     showProduct(0);
     bindData(products);
 }
        public ActionResult Index()
        {
            CategorieClient _categorieClient = new CategorieClient();

            ViewBag.listcategorie = _categorieClient.FindAll();
            ProductClient _productClient = new ProductClient();

            ViewBag.listProduct = _productClient.FindAll();
            return(View());
        }
        public ActionResult SearchByCatigory(int id = 0)
        {
            CategorieClient _categorieClient = new CategorieClient();

            ViewBag.listcategorie = _categorieClient.FindAll();
            ProductClient _productClient = new ProductClient();

            ViewBag.listProduct = _productClient.FindCategory(id);
            return(View("index"));
        }
Esempio n. 20
0
        static void Main(string[] args)
        {
            string baseUri = "http://localhost:9000";

            Console.WriteLine("Fetching products");
            var            consumer = new ProductClient();
            List <Product> result   = consumer.GetProducts(baseUri).GetAwaiter().GetResult();

            Console.WriteLine(result);
        }
Esempio n. 21
0
        public void Create_Product()
        {
            ProductServiceReference.ProductClient product = new ProductClient("BasicHttpBinding_IProduct");
            product.Open();
            product.Create(_dto);

            ProductDTO result = product.Read(_dto.Id);

            Assert.IsNotNull(result);
        }
Esempio n. 22
0
        public ActionResult Update(int id)
        {
            List <ProductReview> CVM = new List <ProductReview>();
            ProductClient        CC  = new ProductClient();

            CVM = CC.find(id).ToList();
            ProductReview preview = CVM.First(e => e.Reviews_Id == e.Reviews_Id);

            return(View(preview));
        }
Esempio n. 23
0
        public void TestMethod1()
        {
            var client = new ProductClient();

            client.AddAsync(new Product {
                Name = "Product #12", Price = 1.23m, Count = 8
            }).Wait();

            var products = client.GetAllAsync().Result;
        }
Esempio n. 24
0
        public Order()
        {
            InitializeComponent();

            orderService   = new OrderClient();
            accountService = new AccountClient();
            productService = new ProductClient();
            orders         = new List <OrderModel>();
            threadInit.RunWorkerAsync();
        }
Esempio n. 25
0
        public async Task <IEnumerable <Candle> > Get(string id)
        {
            _logger.LogInformation($"Retrieving historic rates of {id.ToUpper()}-EUR");

            var client   = new ProductClient("https://api.gdax.com", _authenticator);
            var response = await client.GetHistoricRatesAsync($"{id.ToUpper()}-EUR", DateTimeOffset.UtcNow.AddDays(-7),
                                                              DateTimeOffset.UtcNow, TimeSpan.FromDays(1));

            return(response);
        }
Esempio n. 26
0
        public Order()
        {
            InitializeComponent();

            orderService = new OrderClient();
            accountService = new AccountClient();
            productService = new ProductClient();
            orders = new List<OrderModel>();
            threadInit.RunWorkerAsync();
        }
Esempio n. 27
0
        public StartingForm()
        {
            InitializeComponent();

            try
            {
                //Get all Products
                DataHolders.ProductsHolder.products = ProductClient.GetProducts();

                //Get all connections
                DataHolders.ButtonConnectionHolder.connections      = ButtonsClient.GetButtonConnections();
                DataHolders.UnitProductConnectionHolder.Connections = ButtonsClient
                                                                      .GetUnitPorductConnections();

                //Documents
                DataHolders.DocumentConnectionHolder.documentProductConnections = DocumentClient
                                                                                  .GetAllDocumnetProductConnections();

                //Warehouse
                DataHolders.WarehouseHolder.warehouses = DatabaseManagers.WarehouseClient.GetWarehouses();


                //DatabaseManagers.WarehouseManager.GetWarehouses();
                DataHolders.WarehouseHolder.warehouseProductConnections = DatabaseManagers.WarehouseClient
                                                                          .GetWarehouseProductConnection();

                //workers
                DataHolders.WorkerHolder.workers          = WorkerClient.GetWorkers();
                DataHolders.WorkerHolder.avaliableWorkers = WorkerClient.GetAavalibleWorkers();

                //Delivery
                DataHolders.DeliveryHolder.partners          = DeliveryClient.GetPartners();
                DataHolders.DeliveryHolder.locations         = DeliveryClient.GetLocations();
                DataHolders.DeliveryHolder.vehicles          = DeliveryClient.GetVehicles();
                DataHolders.DeliveryHolder.routes            = DeliveryClient.GetRoutes();
                DataHolders.DeliveryHolder.avaliableVehicles = DeliveryClient.GetAvalibleVehicles();

                //properties
                if (PropertiesClient.GetProperties().Exists((e) => e.name == Enums.PropertyName.distance))
                {
                    DataHolders.PropertiesHolder.distanceUnit = PropertiesClient.GetProperties()
                                                                .Find((e) => e.name == Enums.PropertyName.distance).value;
                }
                if (PropertiesClient.GetProperties().Exists((e) => e.name == Enums.PropertyName.weight))
                {
                    DataHolders.PropertiesHolder.weightUnit = PropertiesClient.GetProperties()
                                                              .Find((e) => e.name == Enums.PropertyName.weight).value;
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Error connecting to database, initial data couldn't be load");
                Environment.Exit(1);
            }
        }
Esempio n. 28
0
        static void Main(string[] args)
        {
            Client client = new Client();

            // This way the client code can support the simple leaf
            // components...
            Leaf leaf = new Leaf();

            Console.WriteLine("Client: I get a simple component:\n");
            client.ClientCode(leaf);

            // ...as well as the complex composites.
            Composite tree    = new Composite();
            Composite branch1 = new Composite();

            branch1.Add(new Leaf());
            branch1.Add(new Leaf());
            Composite branch2 = new Composite();

            branch2.Add(new Leaf());
            tree.Add(branch1);
            tree.Add(branch2);
            Console.WriteLine("Client: Now I've got a composite tree:\n");
            client.ClientCode(tree);

            Console.Write("Client: I don't need to check the components classes even when managing the tree:\n");
            client.ClientCode2(tree, leaf);


            Console.WriteLine("Price Calc:\n");
            ProductClient productClient = new ProductClient();


            Product product = new Product(10);

            Console.WriteLine("Client: I get a simple component:\n");
            productClient.ClientCode(product);

            // ...as well as the complex composites.
            Box box      = new Box();
            Box envelop1 = new Box();

            envelop1.Add(new Product(20));
            envelop1.Add(new Product(30));
            Box envelop2 = new Box();

            envelop2.Add(new Product(50));
            box.Add(envelop1);
            box.Add(envelop2);
            Console.WriteLine("Client: Now I've got a composite tree:\n");
            productClient.ClientCode(box);

            Console.Write("Client: I don't need to check the components classes even when managing the tree:\n");
            productClient.ClientCode2(box, product);
        }
Esempio n. 29
0
        public async Task <IHttpActionResult> GetProductClient(int id)
        {
            ProductClient productClient = await db.ProductsClient.FindAsync(id);

            if (productClient == null)
            {
                return(NotFound());
            }

            return(Ok(productClient));
        }
Esempio n. 30
0
 private void btnSaveProducts_Click(object sender, EventArgs e)
 {
     try
     {
         ProductClient.UpdateProduct(GetProductFromForm());
     }
     catch (Exception)
     {
         MessageBox.Show("Failed to update product");
     }
 }
Esempio n. 31
0
        public async Task <IHttpActionResult> PostProductClient(ProductClient productClient)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.ProductsClient.Add(productClient);
            await db.SaveChangesAsync();

            return(CreatedAtRoute("DefaultApi", new { id = productClient.ID }, productClient));
        }
Esempio n. 32
0
 private void btnRefresh_Click(object sender, EventArgs e)
 {
     try
     {
         ProductsHolder.products = ProductClient.GetProducts();
     }
     catch (Exception)
     {
         MessageBox.Show("Failed to refresh from database");
     }
     dgvProducts.DataSource = ProductsHolder.products;
 }
        /// <summary>
        /// 获取未过期要提醒的团信息
        /// </summary>
        /// <returns></returns>
        private static IEnumerable <ExpiredGroupBuyingInfo> GetNotExpiredRemindGroupBuyingInfos()
        {
            var preList = new List <ExpiredGroupBuyingInfo>();
            var list    = DalGroupBuying.GetActiveGroupBuyingInfo().ToList();

            using (var client = new ProductClient())
            {
                var result = client.SelectSkuProductListByPids(list.Select(_ => _.PID).Distinct().ToList());
                if (result.Success && result.Result.Any())
                {
                    foreach (var info in list)
                    {
                        info.IsActive = result.Result.FirstOrDefault(_ => _.Pid.Equals(info.PID))?.Onsale ?? false;
                    }
                }
            }
            using (var cacheClient = CacheHelper.CreateCacheClient())
            {
                var result = cacheClient.Get <List <ExpiredGroupBuyingInfo> >(PreGroupBuyingInfoCacheName);
                if (result.Success && result.Value?.FirstOrDefault() != null)
                {
                    preList.AddRange(result.Value);
                }
                else
                {
                    Logger.Warn($"获取缓存失败,{result.Message}", result.Exception);
                }
                cacheClient.Set(PreGroupBuyingInfoCacheName, list, TimeSpan.FromHours(24.2));
            }

            var infos = new List <ExpiredGroupBuyingInfo>();

            // 库存为0的情况
            foreach (var info in list.Where(_ => _.CurrentSoldCount >= _.TotalStockCount))
            {
                if (preList.Any(_ => _.TotalStockCount > _.CurrentSoldCount && _.ProductGroupId.Equals(info.ProductGroupId) && _.PID.Equals(info.PID)))
                {
                    info.TriggerType = "商品库存不足";
                    infos.Add(info);
                }
            }
            // 产品库商品下架
            foreach (var info in list.Where(_ => !_.IsActive))
            {
                if (preList.Any(_ => _.IsActive && _.ProductGroupId.Equals(info.ProductGroupId) && _.PID.Equals(info.PID)))
                {
                    info.TriggerType = "产品库商品下架";
                    infos.Add(info);
                }
            }
            return(infos);
        }
Esempio n. 34
0
        public PartialViewResult MostPurchasedItem()
        {
            List<ProductOrder> poList = new ProductClient().GetMostPurchasedItem().ToList();
            Product p;
            ProductOrder po = new ProductOrder();
            foreach (ProductOrder prodOrder in poList)
            {
                po = prodOrder;
            }
            p = new ProductClient().GetProductByID(po.ProductID);

            return PartialView("_mostPurchasedItem", p);
        }
Esempio n. 35
0
        public PartialViewResult ProductWithMostFaults()
        {
            List<Fault> poList = new ProductClient().GetProductWithMostFaults().ToList();
            Product p;
            Fault f = new Fault();
            foreach (Fault tempF in poList)
            {
                f = tempF;
            }
            p = new ProductClient().GetProductByID(f.ProductID);

            return PartialView("_productWithMostFaults", p);
        }
Esempio n. 36
0
        public static ProductModel GetProduct(string pid)
        {
            ProductModel product = null;

            using (var productClient = new ProductClient())
            {
                var productResult = productClient.FetchProduct(pid);
                productResult.ThrowIfException(true);
                product = productResult.Result;
            }

            return(product);
        }
Esempio n. 37
0
        public PartialViewResult HighestRatedItem()
        {
            List<Rating> ratings = new ProductClient().GetHighlyRatedItem().ToList();
            Product p;
            Rating r = new Rating();
            foreach (Rating rate in ratings)
            {
                r = rate;
            }

            p = new ProductClient().GetProductByID(r.ProductID);
            ViewBag.Rating = r.Rating1;

            return PartialView("_highestRatedItem", p);
        }
Esempio n. 38
0
        public AddProduct(int mode, long product = 0)
        {
            InitializeComponent();

            catSV = new CategoryClient();
            initLoaiSP();

            this.mode = mode;
            if (mode == 1)
                sBtn = "Thêm sản phẩm";
            if (mode == 2)
            {
                entity.id = product;
                sBtn = "Cập nhật sản phẩm";
                ProductClient sv = new ProductClient();
                Product p = sv.findById(product);
                if (p.Thumbnail != null)
                {
                    existThumbnail = p.Thumbnail;
                    threadLoadImage.RunWorkerAsync(p.Thumbnail);
                }

                txtName.Text = p.Name;
                txtDongia.Text = p.Price.Value.ToString();
                txtGiagiam.Text = p.PromotionPrice.HasValue ? p.PromotionPrice.Value.ToString() : "";
                numSoluong.Value = p.Quantity.Value;
                chbHienthi.Checked = p.ShowOnHome.Value;
                chbHoatdong.Checked = p.Status.Value;

                for (int i = 0; i < cats.Length; i++)
                {
                    if (cats[i].id == p.Category)
                    {
                        cbLoai.SelectedIndex = i;
                        break;
                    }
                }

                foreach (var element in XElement.Parse(p.Description).Elements())
                {
                    gvDescription.Rows.Add(element.Attribute("title").Value, element.Value);
                }

            }
            btnUpdate.Text = sBtn;
        }
Esempio n. 39
0
        public ActionResult Search(string category, string name, string priceFrom, string priceTo)
        {
            if (Session["accountID"] != null)
            {
                if ((category != null || category != "") && (name == null || name == "") && (priceFrom == null || priceFrom == "") && (priceTo == null || priceTo == ""))
                {
                    //With Category
                    Category c = new ProductClient().getCategoryByName(category.ToString());
                    productList = new ProductClient().GetProductsByCategory(c.ID).ToList();

                    return View("Index", productList);
                }
                else if ((category == null || category == "") && (name != null || name != "") && (priceFrom == null || priceFrom == "") && (priceTo == null || priceTo == ""))
                {
                    //With name
                    productList = new ProductClient().GetProductsByName(name).ToList();

                    return View("Index", productList);
                }
                else if ((category == null || category == "") && (name == null || name == "") && (priceFrom != null || priceFrom != "") && (priceTo != null || priceTo != ""))
                {
                    //With prices
                    decimal from = Convert.ToDecimal(priceFrom);
                    decimal to = Convert.ToDecimal(priceTo);

                    productList = new ProductClient().GetProductsByPriceRange(from, to).ToList();

                    return View("Index", productList);
                }
                else
                {
                    return View("Index", new List<Product>());
                }
            }
            else
            {
                return RedirectToAction("Login", "Login");
            }
        }
Esempio n. 40
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            btnUpdate.Enabled = false;
            ProductClient sv;
            switch (mode)
            {
                case 1:
                    // Thêm sản phẩm
                    LoadEntity();
                    if (filename != "")
                        entity.Thumbnail = UploadImage();
                    sv = new ProductClient();

                    if (sv.insert(entity) > -1)
                        MessageBox.Show("Thành công");
                    else
                        MessageBox.Show("Thất bại");
                    btnUpdate.Enabled = true;
                    break;
                case 2:
                    LoadEntity();
                    entity.ModifiedAt = DateTime.Now;
                    entity.ModifiedBy = CurrentUser.Username;
                    if (filename != "")
                        entity.Thumbnail = UploadImage();
                    sv = new ProductClient();
                    if (sv.update(entity))
                        MessageBox.Show("Thành công");
                    else
                        MessageBox.Show("Thất bại");
                    btnUpdate.Enabled = true;
                    break;
            }
        }
Esempio n. 41
0
        public ActionResult ShowReport(int pID, int oID)
        {
            try
            {
                PrintStatementModel model = new PrintStatementModel();
                Order o = new OrderClient().GetOrderByID(oID);
                model.myOrder = o;

                ProductOrder po = new OrderClient().GetProductOrderByOrderIDAndProductID(o.ID, pID);
                model.myProductOrder = po;

                List<FaultLog> fl = new List<FaultLog>();

                Product p = new ProductClient().GetProductByID(pID);
                model.myProduct = p;

                List<Fault> f = new FaultClient().GetFaultsByAccountIDandProductID((int)Session["accountID"], pID).ToList();
                model.myFaultList = f;

                Common.FaultLog faultLog = new Common.FaultLog();
                List<Common.FaultLog> faultLogList = new List<Common.FaultLog>();
                List<Common.Fault> flist = new List<Common.Fault>();

                flist = new DSA_Assignment1_Sit1.FaultServ.FaultClient().GetFaultsByAccountIDandProductID((int)Session["accountID"], pID).ToList();

                foreach (Common.Fault fa in flist)
                {
                    List<Common.FaultLog> flTemp = new DSA_Assignment1_Sit1.FaultServ.FaultClient().GetAllFaultLogsByFaultID(fa.ID).ToList();

                    model.myFaultLog = flTemp;
                }

                if (model.myFaultLog == null)
                {
                    List<Order> orderList = new OrderClient().GetBoughtOrdersByAccountID((int)Session["accountID"]).ToList();

                    foreach (Order or in orderList)
                    {
                        List<ProductOrder> productOrderlist = new OrderClient().GetProductOrderByOrderID(or.ID).ToList();

                        foreach (ProductOrder por in productOrderlist)
                        {
                            allPO.Add(por);
                        }
                    }

                    ViewBag.Error = "No fault logs recorded.";
                    return RedirectToAction("PurchaseHistory", allPO);
                }
                //SEND EMAIL

                //get user email
                User user = new UserAccountClient().GetUserByAccountID((int)Session["accountID"]);

                //Render email

                Document document = new Document();
                MemoryStream memoryStream = new MemoryStream();
                PdfWriter writer = PdfWriter.GetInstance(document, memoryStream);

                document.Open();
                document.Add(new Paragraph("Electros Ltd."));
                document.Add(new Paragraph());
                document.Add(new Paragraph("Item: "));
                document.Add(new Paragraph("Product ID          " + "Name                    " + "Price          " + "Date Of Purchase         " + "Warranty Expiry"));
                document.Add(new Paragraph(model.myProduct.ID + "                    " + model.myProduct.Name + "          " + model.myProduct.Price + "          " + model.myOrder.DateOfOrder.ToShortDateString() + "             " + model.myProductOrder.WarrantyExpiry.ToShortDateString()));
                document.Add(new Paragraph());
                document.Add(new Paragraph("Faults: "));
                document.Add(new Paragraph("Fault ID          Date          Fault Details                              Status"));
                foreach (FaultLog flo in model.myFaultLog)
                {
                    document.Add(new Paragraph(flo.FaultID + "          " + flo.DateOfReport.ToShortDateString() + "          " + flo.Description + "                              " + flo.Status));
                }
                writer.CloseStream = false;
                document.Close();
                memoryStream.Position = 0;

                MailMessage newMessage = new MailMessage();
                newMessage.From = new MailAddress("*****@*****.**");
                newMessage.To.Add(new MailAddress(user.Email));
                newMessage.Subject = "Print Statement";
                newMessage.Body = "Dear " + user.Name + " " + user.Surname + ",  please find attached details of the product's faults.";
                Attachment attachment = new Attachment(memoryStream, "ReportStatement.pdf");
                newMessage.Attachments.Add(attachment);
                SmtpClient smtpClient = new SmtpClient("smtp.go.net.mt");
                smtpClient.Send(newMessage);

                return new RazorPDF.PdfResult(model, "ShowReport");
            }
            catch (Exception e)
            {
                List<Order> orderList = new OrderClient().GetBoughtOrdersByAccountID((int)Session["accountID"]).ToList();

                foreach (Order o in orderList)
                {
                    List<ProductOrder> productOrderlist = new OrderClient().GetProductOrderByOrderID(o.ID).ToList();

                    foreach (ProductOrder po in productOrderlist)
                    {
                        allPO.Add(po);
                    }
                }
                ViewBag.Error = "An error has occured.";
                return RedirectToAction("PurchaseHistory" , allPO);
            }
        }
Esempio n. 42
0
        public ActionResult PostComment(CommentModel model, int pID)
        {
            try
            {
                if (Session["accountID"] != null)
                {
                    Rating rating = new Rating();
                    Rating tempR = new ProductClient().GetRatingByAccountAndProduct((int)Session["accountID"], pID);

                    if (tempR == null)
                    {
                        rating.ProductID = pID;
                        rating.AccountID = (int)Session["accountID"];
                        rating.Rating1 = model.rating;

                        Comment comment = new Comment();
                        comment.AccountID = (int)Session["accountID"];
                        comment.ProductID = pID;
                        comment.Comment1 = model.commnet;

                        new ProductCommentClient().AddComment(comment);
                        new ProductClient().AddRating(rating);
                        return RedirectToAction("PurchaseHistory");
                    }
                    else
                    {
                        ViewBag.Error = "You already posted a rating for this product.";
                        return View("PostComment", model);
                    }
                }
                else
                {
                    return RedirectToAction("Login", "Login");
                }
            }
            catch (Exception e)
            {
                ViewBag.Error = "An error has occured.";
                return View("PostComment", model);
            }
        }
Esempio n. 43
0
 public ActionResult PostComment(int pID)
 {
     Product p = new ProductClient().GetProductByID(pID);
     CommentModel cm = new CommentModel();
     cm.myProduct = p;
     return View(cm);
 }
Esempio n. 44
0
        public ActionResult Index()
        {
            if (Session["accountID"] != null)
            {
                Order order = new OrderClient().GetOrderByAccountAndStatus((int)Session["accountID"], new OrderClient().GetOrderStatusByName("Cart").ID);
                if (order != null)
                {
                    List<ProductOrder> productList = new OrderClient().GetProductOrderByOrderID(order.ID).ToList();

                    double totalPrice = 0.0;

                    foreach (ProductOrder po in productList)
                    {
                        Product p = new ProductClient().GetProductByID(po.ProductID);
                        totalPrice += (Convert.ToDouble(p.Price) * po.Quantity);
                    }
                    ViewBag.TotalPrice = "Total Order Price: " +  totalPrice.ToString();
                    return View("Index", productList);
                }
                else
                {
                    return View("Index", new List<ProductOrder>());
                }
            }
            else
            {
                return RedirectToAction("Login", "Login");
            }
        }
Esempio n. 45
0
        public void test_product_client_connection()
        {
            ProductClient proxy = new ProductClient();

            proxy.Open();
        }
        public ActionResult Search(string category, string name, string priceFrom, string priceTo)
        {
            if (Session["accountID"] != null)
            {
                if ((category != null || category != "") && (name == null || name == "") && (priceFrom == null || priceFrom == "") && (priceTo == null || priceTo == ""))
                {
                    //With Category
                    Category c = new ProductClient().getCategoryByName(category.ToString());
                    if (c != null)
                    {
                        productList = new ProductClient().GetProductsByCategory(c.ID).ToList();
                    }
                    else
                    {
                        productList = new ProductClient().GetAllProducts().ToList();
                        ViewBag.Error = "Category not identified.";
                        return View("Index", productList);
                    }
                    return View("Index", productList);
                }
                else if ((category == null || category == "") && (name != null || name != "") && (priceFrom == null || priceFrom == "") && (priceTo == null || priceTo == ""))
                {
                    //With name
                    productList = new ProductClient().GetProductsByName(name).ToList();

                    if (productList.Count <= 0)
                    {
                        productList = new ProductClient().GetAllProducts().ToList();
                        ViewBag.Error = "No products retrieved with that name.";
                        return View("Index", productList);
                    }
                    else
                    {
                        return View("Index", productList);
                    }
                }
                else if ((category == null || category == "") && (name == null || name == "") && (priceFrom != null || priceFrom != "") && (priceTo != null || priceTo != ""))
                {
                    try
                    {
                        Convert.ToDecimal(priceFrom);
                        Convert.ToDecimal(priceTo);
                    }
                    catch (Exception e)
                    {
                        productList = new ProductClient().GetAllProducts().ToList();
                        ViewBag.Error = "Price not in correct format.";
                        return View("Index", productList);
                    }
                    //With prices
                    decimal from = Convert.ToDecimal(priceFrom);
                    decimal to = Convert.ToDecimal(priceTo);

                    productList = new ProductClient().GetProductsByPriceRange(from, to).ToList();

                    return View("Index", productList);
                }
                else
                {
                    return View("Index", new List<Product>());
                }
            }
            else
            {
                return RedirectToAction("Login", "Login");
            }
        }
        public ActionResult Details(int id)
        {
            double rating = new ProductClient().GetRatingsByProduct(id);

            Product pro = new ProductClient().GetProductByID(id);
            ViewAllProductModel m = new ViewAllProductModel();
            m.myProduct = pro;
            m.rating = rating;
            return View(m);
        }
Esempio n. 48
0
 private void menuGridView_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
 {
     long id = products[gvProduct.CurrentRow.Index].id;
     menuGridView.Hide();
     switch (e.ClickedItem.ToString())
     {
         case "Chỉnh sửa":
             AddProduct frm = new AddProduct(2, id);
             frm.Show();
             break;
         case "Xoá":
             DialogResult rs = MessageBox.Show("Bạn chắc chắn xoá?", "Thông báo", MessageBoxButtons.OKCancel);
             if (rs == DialogResult.OK)
             {
                 ProductClient sv = new ProductClient();
                 if (sv.delete(id)) {
                     MessageBox.Show("Thành công");
                 }
                 else
                     MessageBox.Show("Thất bại");
             }
             break;
     }
 }
Esempio n. 49
0
 private void threadInit_DoWork(object sender, DoWorkEventArgs e)
 {
     sv = new ProductClient();
     svCat = new CategoryClient();
     products = sv.findAll();
     threadInit.ReportProgress(60);
     categories = svCat.findAll();
     threadInit.ReportProgress(100);
 }
Esempio n. 50
0
 public ActionResult Details(int id)
 {
     Product pro = new ProductClient().GetProductByID(id);
     ViewAllProductModel m = new ViewAllProductModel();
     m.myProduct = pro;
     return View(m);
 }