Example #1
0
 public CustomerTest()
 {
     //
     // TODO: Add constructor logic here
     //
     CustomerControllerInstance = new ApiCustomerController();
 }
Example #2
0
        //[HttpGet]
        public async Task <IActionResult> Index()
        {
            int    customerId            = 0;
            string username              = "******"; //just for this demo application
            List <ModelInventory> result = null;
            int countOrdered             = 0;

            string culture     = "en";
            var    cultureInfo = new CultureInfo(culture);

            cultureInfo.NumberFormat.CurrencySymbol   = "€";
            CultureInfo.DefaultThreadCurrentCulture   = cultureInfo;
            CultureInfo.DefaultThreadCurrentUICulture = cultureInfo;
            Thread.CurrentThread.CurrentCulture       = CultureInfo.CreateSpecificCulture(culture);
            Thread.CurrentThread.CurrentUICulture     = CultureInfo.CreateSpecificCulture(culture);


            string token = "";

            if (HttpContext != null)
            {
                // actually it is a demo variant of registration
                ApiCustomerController apiCustomerController = new ApiCustomerController(apiCustomerRepository);
                var resultRegister = await apiCustomerController.RegisterOrModify(username);

                if (resultRegister == null)
                {
                    ViewBag.StatusMessage = localizer["BadRegistration"].Value;
                }
                else
                {
                    customerId = resultRegister.CustomerId;
                }

                token = HttpContext.Session.GetString("token");
                if (string.IsNullOrEmpty(token))
                {
                    Token t = new Token();
                    token = t.CreateToken();
                    HttpContext.Session.SetString("token", token);

                    cacheData(token, customerId);
                }
                ViewBag.Token = token;
                HttpContext.Session.SetInt32("customerId", customerId);
            }
            if (localizer != null)
            {
                ViewData["Title"]    = localizer["Title"].Value;
                ViewBag.NotFound     = localizer["NotFound"].Value;
                ViewBag.Name         = localizer["Name"].Value;
                ViewBag.Type         = localizer["Type"].Value;
                ViewBag.Duration     = localizer["Duration"].Value;
                ViewBag.Days         = localizer["Days"].Value;
                ViewBag.AddCart      = localizer["AddCart"].Value;
                ViewBag.ErrorApiCall = localizer["ErrorApiCall"].Value;
                ViewBag.Cart         = localizer["ShoppingCart"].Value;
                ViewBag.OpenCart     = localizer["OpenCart"].Value;
                ViewBag.WrongInput   = localizer["WrongInput"].Value;
            }

            try
            {
                ApiInventoryController             apiInventoryController = new ApiInventoryController(localizer);
                Tuple <List <ModelInventory>, int> tuple = await apiInventoryController.Get(token);

                result               = tuple.Item1;
                countOrdered         = tuple.Item2;
                ViewBag.CountOrdered = countOrdered;

                return(View(result));
            }
            catch (Exception ex)
            {
                logger.LogError(ex.Message + "; " + ex.InnerException);
                ViewBag.StatusMessage = ex.Message + "<br />" + ex.InnerException;
                return(View());
            }
        }
        public async Task <IActionResult> Order(string token)
        {
            string           priceCur = ConstClass.priceCurrency;
            int              count = 0, loyaltyPoints = 0;
            decimal          total           = 0;
            int              customerId      = 0;
            List <ModelCart> list            = null;
            CalculateViewer  calculateViewer = new CalculateViewer(new Calculate());
            StringBuilder    strb            = new StringBuilder();

            ModelParameters modelParameters = cache.Get <ModelParameters>("globalParams");

            if (modelParameters != null)
            {
                token      = modelParameters.Token;
                customerId = modelParameters.CustomerId;
            }

            if (localizer != null)
            {
                ViewData["Title"]          = localizer["Title"].Value;
                ViewBag.Name               = localizer["Name"].Value;
                ViewBag.Type               = localizer["Type"].Value;
                ViewBag.Duration           = localizer["Duration"].Value;
                ViewBag.DateOrderLabel     = localizer["DateOrder"].Value;
                ViewBag.ProductsCountLabel = localizer["ProductsCount"].Value;
                ViewBag.CustomerNameLabel  = localizer["Customer"].Value;
                ViewBag.LoyaltyPointsLabel = localizer["LoyaltyPoints"].Value;
                ViewBag.StartNewOrder      = localizer["StartNewOrder"].Value;
                ViewBag.Download           = localizer["Download"].Value;
                ViewBag.Print              = localizer["Print"].Value;
            }

            try
            {
                ApiOrderController orderController = new ApiOrderController(apiOrderRepository);
                Tuple <List <ModelCart>, BondoraOrder, BondoraCustomer> tuple = await orderController.Get(token);

                if (tuple != null)
                {
                    list = tuple.Item1;
                    BondoraOrder    order    = tuple.Item2;
                    BondoraCustomer customer = tuple.Item3;
                    if (logger != null)
                    {
                        logger.LogInformation("ApiOrderController result: {0}", list);
                    }

                    if (list == null)
                    {
                        ViewBag.StatusMessage = localizer["NotFound"].Value;
                    }
                    else
                    {
                        ViewBag.ProductsCount = list.Count();
                        if (order != null)
                        {
                            ViewBag.OrderTitle = localizer["OrderNo"].Value + " " + order.OrderId;
                            ViewBag.DateOrder  = order.DateOrder;
                        }
                        if (customer != null)
                        {
                            ViewBag.CustomerName = customer.Username;
                        }


                        strb.Append("<br /><table width='100%'>");
                        strb.Append("<tr><th>" + localizer["Name"].Value + "</th><th>" + localizer["Type"].Value + "</th><th>" + localizer["Days"].Value + "</th><th>" + localizer["Price"].Value + "</th></tr>");
                        foreach (var item in list)
                        {
                            count         += 1;
                            loyaltyPoints += calculateViewer.CalculatePoints(item.TypeId);
                            item.Price     = calculateViewer.CalculatePrices(item.TypeId, item.Days);
                            item.PriceCur  = priceCur;
                            total         += item.Price;

                            strb.Append("<tr bgcolor='" + IsParity(2, count - 1) + "'><td>" + item.Name + "</td><td>" + item.TypeName + "</td><td>" + item.Days + "</td><td>" + item.Price + " " + item.PriceCur + "</td></tr>");
                        }
                        strb.Append("<tr><td colspan=2></td><td align=right>" + localizer["Total"].Value + ":</td><td class='price'>" + total + " " + priceCur + "</td></tr>");
                        strb.Append("</table>");
                        ViewBag.OrderProducts = strb.ToString();
                        ViewBag.LoyaltyPoints = loyaltyPoints;

                        ApiCustomerController apiCustomerController = new ApiCustomerController(apiCustomerRepository);
                        await apiCustomerController.updateLoyalty(customerId, loyaltyPoints);
                    }
                }
                return(View(list));
            }
            catch (Exception ex)
            {
                logger.LogError(ex.Message + "; " + ex.InnerException);
                ViewBag.StatusMessage = ex.Message + "<br />" + ex.InnerException;
                return(View());
            }
        }