Exemple #1
0
        /// <summary>
        /// Method for saving a list of items
        /// </summary>
        /// <param name="models">The list of models to be saved</param>
        /// <returns>An empty task</returns>
        public async Task SaveBulkAsync(List <T> models)
        {
            CustomerProductController controller = new CustomerProductController();

            foreach (var model in models)
            {
                await this.SaveAsync(model);

                Customer customer = model as Customer;
                if (customer == null)
                {
                    continue;
                }

                SequentialGuid.GuidGen++;
                CustomerProduct cp = new CustomerProduct
                {
                    Id            = SequentialGuid.GuidGen.CurrentGuid,
                    CustomerId    = customer.Id,
                    DisplayName   = customer.Product.DisplayName,
                    ProductTypeId = customer.Product.ProductTypeId,
                    DateAcquired  = customer.Product.DateAcquired,
                    SerialNumber  = customer.Product.SerialNumber
                };

                await controller.SaveCustomerProductToDevice(cp);
            }
        }
        public async Task <IActionResult> Create(CustomerProduct customerProduct)
        {
            if (ModelState.IsValid)
            {
                CustomerProduct cp1 = customerProduct;
                Product         p1  = new Product(_context);
                //customerProduct.Price = p1.getPrice(customerProduct.ProductId);
                double product = _context.Product.Where(P => P.Id == customerProduct.ProductId).Select(P => P.Price).FirstOrDefault();

                //var price = _context.products.Where(P => P.Id == customerProduct.ProductId).Include(P => P.Price).Select(P => P.Price);
                //customerProduct.Price = product;
                cp1.ProductId  = customerProduct.ProductId;
                cp1.CustomerId = customerProduct.CustomerId;
                cp1.Price      = product;
                cp1.Order_date = customerProduct.Order_date;

                _context.Add(cp1);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CustomerId"] = new SelectList(_context.Customer, "Id", "Id", customerProduct.CustomerId);
            ViewData["ProductId"]  = new SelectList(_context.Set <Product>(), "Id", "Id", customerProduct.ProductId);
            return(View(customerProduct));
        }
        /// <summary>
        /// Saves the customers selected product to the device
        /// </summary>
        /// <param name="customerId">The customer's ID</param>
        /// <param name="tran">The transaction in which to run</param>
        /// <returns>A void task</returns>
        private async Task SaveCustomerProductToDevice(Guid customerId, SQLiteConnection tran)
        {
            CustomerProduct cutomerProduct = JsonConvert.DeserializeObject <CustomerProduct>(JsonConvert.SerializeObject(this.personRegistrationInfo.Product));

            cutomerProduct.CustomerId = customerId;
            await new CustomerProductController().SaveAsync(tran, cutomerProduct);
        }
        public async Task <IActionResult> Edit(int id, [Bind("CustomerId,ProductId,Price,Order_date")] CustomerProduct customerProduct)
        {
            if (id != customerProduct.CustomerId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(customerProduct);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CustomerProductExists(customerProduct.CustomerId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CustomerId"] = new SelectList(_context.Customer, "Id", "Id", customerProduct.CustomerId);
            ViewData["ProductId"]  = new SelectList(_context.Set <Product>(), "Id", "Id", customerProduct.ProductId);
            return(View(customerProduct));
        }
        public void ItShouldReturnPadLeftParamIfIsValid(string productNumber, string customerId,
                                                        int customerFieldLength, int productFieldLength, string expectedCustomer, string expectedProduct)
        {
            //Arrange
            CustomerProduct customerProduct = new CustomerProduct
            {
                ProductNumber = productNumber
            };

            Customer customer = new Customer
            {
                CustomerID = customerId
            };

            CustomerRequest request = new CustomerRequest
            {
                CustomerProduct       = customerProduct,
                Customer              = customer,
                customerIDFieldLength = customerFieldLength,
                productFieldLength    = productFieldLength
            };

            WithCodeSmells wcs = new WithCodeSmells();

            //Act
            wcs.ValidateRequest(request);

            //Assert
            Assert.AreEqual(expectedCustomer, request.Customer.CustomerID);
            Assert.AreEqual(expectedProduct, request.CustomerProduct.ProductNumber);
        }
Exemple #6
0
        public List <CustomerProduct> getCPCdomainProduct(string cPCName)
        {
            SqlCommand dinsert = new SqlCommand("usp_GetCPCDomainProduct");

            dinsert.Parameters.AddWithValue("@CPCName", SqlDbType.VarChar).Value = cPCName;
            DataSet dtList = objcon.GetDsByCommand(dinsert);
            List <CustomerProduct> list1 = new List <CustomerProduct>();

            foreach (DataRow dr in dtList.Tables[0].Rows)
            {
                CustomerProduct pd = new CustomerProduct();


                pd.ProductName          = (dr["ProductName"].ToString());
                pd.ProductPrise         = (dr["ProductPrise"].ToString());
                pd.DomainCreationDate   = dr["DomainCreationDate"].ToString();
                pd.DomainExpirationDate = dr["DomainExpirationDate"].ToString();
                pd.CustDomainProductId  = Convert.ToInt32(dr["CustDomainProductId"].ToString());
                pd.DomainDeletionDate   = dr["DomainDeletionDate"].ToString();
                pd.OrderDate            = dr["OrderDate"].ToString();
                pd.OrderDate            = dr["OrderDate"].ToString();
                list1.Add(pd);
            }
            return(list1);
        }
        public List <CustomerProductModel> DeleteCustomerProduct(long Id, long orderId)
        {
            List <CustomerProductModel> lstcsproducts = new List <CustomerProductModel>();

            using (ShopDevEntities db = new ShopDevEntities())
            {
                try
                {
                    CustomerProduct customerProduct = GetCustomerProduct(db, Id);
                    customerProduct.IsActive = false;
                    db.CustomerProducts.Remove(customerProduct);
                    db.SaveChanges();
                    var lstproducts = db.CustomerProducts.Where(m => m.OrderID == orderId && m.IsActive).ToList();
                    foreach (var cusprod in lstproducts)
                    {
                        CustomerProductModel objcsproducts = new CustomerProductModel();
                        cusprod.CopyProperties(objcsproducts);
                        lstcsproducts.Add(objcsproducts);
                    }
                }
                catch (Exception)
                {
                }
                return(lstcsproducts);
            }
        }
        public async Task <ActionResult> GetCustomers(int productid, DateTime start, DateTime end, int pageNo = 1, int pageSize = 10)
        {
            if (start == new DateTime(1, 1, 1, 0, 0, 0))
            {
                start = DateTime.Now.AddDays(-30);
            }
            if (end == new DateTime(1, 1, 1, 0, 0, 0))
            {
                end = DateTime.Now;
            }
            List <CustomerProduct> results = new List <CustomerProduct>();
            var customers = _context.Rfq.Where(r => r.Productid == productid).Select(r => r.Customer);

            foreach (string cus in customers)
            {
                var cusOrder = _context.Rfq.Where(rf => rf.Customer == cus).Select(rf => rf.Rfqid);
                var payLogs  = _context.Paymentlog.Where(pl => cusOrder.Contains(pl.Rfqid) && pl.Status == "accepted" && (pl.Paymentdate >= start && pl.Paymentdate <= end));
                var cp       = new CustomerProduct()
                {
                    Customer = cus,
                    Orders   = payLogs.Count(),
                    Total    = payLogs.Sum(pl => pl.Totalamount),
                };
                var tc = await _context.Customer.SingleOrDefaultAsync(c => c.Email == cus);

                cp.Joindate = tc.Joindate;
                results.Add(cp);
            }
            int skip    = (pageNo - 1) * pageSize;
            var records = results.OrderByDescending(pc => pc.Orders).Skip(skip).Take(pageSize).ToList();

            return(Ok(new PagedResult <CustomerProduct>(records, pageNo, pageSize, results.Count)));
        }
        public void ItShouldReturnExceptionIfAnyParamIsInvalid(string productNumber, string customerId,
                                                               int customerFiedLength, int productFieldLength, string exception)
        {
            //Arrange
            CustomerProduct customerProduct = new CustomerProduct
            {
                ProductNumber = productNumber
            };

            Customer customer = new Customer
            {
                CustomerID = customerId
            };

            CustomerRequest request = new CustomerRequest
            {
                CustomerProduct       = customerProduct,
                Customer              = customer,
                customerIDFieldLength = customerFiedLength,
                productFieldLength    = productFieldLength
            };

            WithCodeSmells wcs = new WithCodeSmells();

            //Assert
            Exception ex = Assert.Throws <Exception>(() => wcs.ValidateRequest(request));

            Assert.That(ex.Message, Is.EqualTo(exception));
        }
Exemple #10
0
 public IActionResult RegProduct(MgrRegistrationModel views)
 {
     try {
         var reg = new CustomerProduct()
         {
             ProductID = views.ProductID, CustomerID = views.CustomerID
         };
         sportsUnit.CustomerProducts.Insert(reg);
         sportsUnit.save();
         return(RedirectToAction("RegProduct", views));
     }
     catch
     {
         int CustomerID = views.CustomerID;
         QueryOptions <CustomerProduct> query = new QueryOptions <CustomerProduct>
         {
             Where    = inc => inc.CustomerID == CustomerID,
             Includes = "Customer, Product"
         };
         ViewBag.Products = sportsUnit.Products.List(new QueryOptions <Product>());
         if (CustomerID == 0)
         {
             return(RedirectToAction("List", "Registration"));
         }
         ViewBag.CustomerName   = sportsUnit.Customers.Get(CustomerID).FullName;
         views.CustomerProducts = sportsUnit.CustomerProducts.List(query);
         return(View(views));
     }
 }
 /// <summary>
 /// Calculate paymount amounts by applying rules
 /// </summary>
 public void Calculate()
 {
     foreach (var rule in rules)
     {
         CustomerProduct = rule.Apply(CustomerProduct);
     }
 }
 public void TestInitialize()
 {
     underTest       = new TotalPremiumRule();
     annualPremium   = 50;
     creditCharge    = 2.5;
     customerProduct = BuildCustomerProduct();
 }
Exemple #13
0
        private void MenuItem_Observe_Click(object sender, RoutedEventArgs e)
        {
            if (listBox_ProductsList.SelectedIndex >= 0)
            {
                var product         = (Product)listBox_ProductsList.SelectedItem;
                var customerProduct = new CustomerProduct {
                    Customer = customer, Product = product
                };

                var allCustomerProducts = database.GetAllCustomerProducts(customer);

                bool isInList = false;
                foreach (var p in allCustomerProducts)
                {
                    if (p.ProductID == product.ProductID)
                    {
                        isInList = true;
                    }
                }

                if (!isInList && product.Quantity <= 0)
                {
                    if (database.AddCustomerProduct(customerProduct))
                    {
                        subscribedProductsList.Add(product);

                        product.Attach(customer);
                    }
                }
            }
        }
        public ActionResult DeleteConfirmed(long id)
        {
            CustomerProduct customerProduct = db.CustomerProducts.Find(id);

            db.CustomerProducts.Remove(customerProduct);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public async Task <CustomerProduct> Add(CustomerProduct product)
        {
            await context.CustomerProducts.AddAsync(product);

            await context.SaveChangesAsync();

            return(product);
        }
Exemple #16
0
 public ActionResult Form(CustomerProduct model)
 {
     ViewBag.Products = products;
     if (model.Products != null && model.Products.Length > 0)
     {
         ViewBag.Message = string.Format(Localization.MultiSelectRes.Form_Message, string.Join(", ", model.Products));
     }
     return(View(model));
 }
Exemple #17
0
 public ProductViewModel(CustomerProduct cp)
 {
     Customerid  = cp.CustomerId;
     Productid   = cp.ProductId;
     NameProduct = cp.Product.NameProduct;
     Description = cp.Product.Description;
     Price       = cp.Product.Price;
     Id          = cp.Product.Id;
 }
 public Payments(CustomerProduct customerProduct)
 {
     CustomerProduct = customerProduct;
     rules.Add(new CreditChargeRule());
     rules.Add(new TotalPremiumRule());
     rules.Add(new AverageMonthlyPremiumRule());
     rules.Add(new InitialMonthlyPaymentAmountRule());
     rules.Add(new OtherMonthlyPaymentsAmountRule());
 }
Exemple #19
0
 /// <summary>
 /// Apply Average Monthly Premium Rule
 /// </summary>
 /// <param name="customerProduct">customer product</param>
 /// <returns>customer product</returns>
 public CustomerProduct Apply(CustomerProduct customerProduct)
 {
     if (customerProduct?.TotalPremium == null)
     {
         throw new RuleException(ErrorMessages.TotalPremium);
     }
     customerProduct.AverageMonthlyPremium = customerProduct.TotalPremium / 12;
     return(customerProduct);
 }
 /// <summary>
 /// Apply Credit Charge Rule
 /// </summary>
 /// <param name="customerProduct">customer product</param>
 /// <returns>customer product</returns>
 public CustomerProduct Apply(CustomerProduct customerProduct)
 {
     if (customerProduct?.AnnualPremium == null)
     {
         throw new RuleException(ErrorMessages.AnnualPremium);
     }
     customerProduct.CreditCharge = Math.Round((customerProduct.AnnualPremium / 100) * 5, 2);
     return(customerProduct);
 }
Exemple #21
0
        /// <summary>
        /// 添加到购物车-首页添加
        /// </summary>
        /// <param name="cvm"></param>
        /// <returns></returns>
        public ActionResult AddWithDefaultProduct(int productId)
        {
            try
            {
                using (LsBuyEntities db = new LsBuyEntities())
                {
                    string defaultColor = "red", defaultImage = "img1", defaultText = "";
                    //获取当前登录用户信息
                    User            user       = db.Users.Where(t => t.UserName == User.Identity.Name).FirstOrDefault();
                    CustomerProduct cutomerPro =
                        db.CustomerProducts.Where(t =>
                                                  t.Color == defaultColor &&
                                                  t.Text == defaultText &&
                                                  t.Image == defaultImage &&
                                                  t.ProductId == productId).FirstOrDefault();
                    if (cutomerPro == null)
                    {
                        CustomerProduct customerPro = new CustomerProduct
                        {
                            Color     = defaultColor,
                            Image     = defaultImage,
                            Text      = defaultText,
                            ProductId = productId,
                        };
                        //添加定制产品
                        db.CustomerProducts.Add(customerPro);
                        db.SaveChanges();
                        //查询定制产品
                        cutomerPro =
                            db.CustomerProducts.Where(t =>
                                                      t.Color == defaultColor &&
                                                      t.Text == defaultText &&
                                                      t.Image == defaultImage &&
                                                      t.ProductId == productId).FirstOrDefault();
                    }

                    //加入购物车
                    ShoppingChart shoppingChart = new ShoppingChart
                    {
                        ProductId   = cutomerPro.Id,
                        UserId      = user.Id,
                        CreatedTime = DateTime.Now
                    };
                    //加入购物车
                    db.ShoppingCharts.Add(shoppingChart);
                    //保存到数据库
                    db.SaveChanges();

                    return(Redirect("AddSuccess"));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// Apply Other Monthly Payments Amount Rule
        /// </summary>
        /// <param name="customerProduct">customer product</param>
        /// <returns>customer product</returns>
        public CustomerProduct Apply(CustomerProduct customerProduct)
        {
            if (customerProduct?.AverageMonthlyPremium == null)
            {
                throw new RuleException(ErrorMessages.AverageMonthlyPremium);
            }

            customerProduct.OtherMonthlyPayments = Math.Round(customerProduct.AverageMonthlyPremium, 2);
            return(customerProduct);
        }
 public ActionResult Edit([Bind(Include = "ProductID,ProductName,OrderID,AppxWeight,ActualWeight,Description,IsActive,CreatedDate,CreatedBy,UpdatedDate,Updatedby")] CustomerProduct customerProduct)
 {
     if (ModelState.IsValid)
     {
         db.Entry(customerProduct).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(customerProduct));
 }
Exemple #24
0
        public ActionResult Form()
        {
            ViewBag.Products = products;
            var model = new CustomerProduct()
            {
                Products = new string[] { }
            };

            return(View(model));
        }
Exemple #25
0
 public void TestGenerateOutputFileWithoutOutputTemplate()
 {
     customerProduct     = BuildCustomerProduct();
     OutputTemplate.Load = null;
     underTest           = new GenerateOutputFile <CustomerProduct>()
     {
         GenericProperty = customerProduct, FileSystem = mockFileSystem.Object, FilePath = filePath
     };
     underTest.Start();
 }
Exemple #26
0
        public void AddProductToCustomer(ProductSingleViewModel model, int customerID)
        {
            CustomerProduct cp = new CustomerProduct();

            cp.CustomerID         = customerID;
            cp.ProductID          = model.ProductID;
            cp.CalculationDetails = false;

            customerProductRepository.Create(cp);
        }
Exemple #27
0
 public bool AddCustomerProduct(CustomerProduct customerProduct)
 {
     using (var context = new DatabaseContext())
     {
         var entity = context.CustomerProducts.Attach(customerProduct);
         entity.State = EntityState.Added;
         context.SaveChanges();
         return(true);
     }
 }
        /// <summary>
        /// Apply Total Premium Rule
        /// </summary>
        /// <param name="customerProduct">customer product</param>
        /// <returns>customer product</returns>
        public CustomerProduct Apply(CustomerProduct customerProduct)
        {
            if (customerProduct?.AnnualPremium == null || customerProduct?.CreditCharge == null)
            {
                throw new RuleException(ErrorMessages.AnnualPremiumOrCreditCharge);
            }

            customerProduct.TotalPremium = customerProduct.AnnualPremium + customerProduct.CreditCharge;
            return(customerProduct);
        }
Exemple #29
0
        public void ChangeCustomerProductCalDetailsValue(CustomerProductSingleViewModel model)
        {
            CustomerProduct cp = new CustomerProduct();

            cp.CustomerProductID  = model.CustomerProductID;
            cp.CustomerID         = model.CustomerID;
            cp.ProductID          = model.ProductID;
            cp.CalculationDetails = model.CalculationDetails;

            customerProductRepository.Update(cp);
        }
        public static CustomerProduct ConvertCustomerProductDTOToCustomerProduct(this CustomerProductDTO customerProductDTO)
        {
            CustomerProduct customerProduct = new CustomerProduct();

            customerProduct.Customer.Id = customerProductDTO.CustomerId;
            customerProduct.Product.Id  = customerProductDTO.ProductId;
            // caso seja preciso, pode ser passado o database por parâmetro e preeencher
            // os outros dados, no momento, não foi preciso

            return(customerProduct);
        }