Exemple #1
0
        public async Task <int> CreateProduct(ProductRequest request)
        {
            await _dbService.DescriptionSave(request.Description);

            await _dbService.PriceSave(request.Price);

            await _dbService.ProductSave(request.Product);

            return(await _context.SaveChangesAsync());
        }
    public async void AddToCart(Guid id)
    {
        //TO DO: IMPLEMENT auth check before DB save
        var     options       = HttpContext.Request.Form.Where(k => k.Key.Contains("Options"));
        decimal totalOptPrice = 0;
        string  optCollection = string.Empty;

        foreach (var opt in options)
        {
            var dbOpt = await _context.ProductOptionParams.Where(p => p.ParameterName == opt.Key).FirstOrDefaultAsync();

            if (dbOpt.ParameterPrice != 0)
            {
                optCollection += $",{dbOpt.ParameterName}";
                totalOptPrice += dbOpt.ParameterPrice;
            }
        }
        //TO DO : Get region from user location
        decimal productPrice = await _context.ProductPrices.Where(p => p.ProductId == id).Select(p => p.UsPrice).FirstOrDefaultAsync() ?? 0;


        //TO DO : fix fake user when auth is implemented
        Order newOrder = new Order
        {
            OrderId     = Guid.NewGuid(),
            CustomerId  = await _context.Customers.Select(c => c.CustomerId).FirstOrDefaultAsync(),
            Total       = CalculateProductTotal(totalOptPrice, productPrice),
            OrderStatus = "Created",//TO DO: Create ENUM
            EmailSended = false
        };

        _context.Orders.Add(newOrder);

        OrderProduct newOrderProduct = new OrderProduct
        {
            OrderProductId            = Guid.NewGuid(),
            OrderId                   = newOrder.OrderId,
            ProductId                 = id,
            ProductOptions            = optCollection,
            ProductCheckoutPrice      = productPrice,
            TotalOptionsCheckoutPrice = totalOptPrice,
        };

        _context.OrderProducts.Add(newOrderProduct);
        await _context.SaveChangesAsync();
    }
Exemple #3
0
        public async Task <IActionResult> Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                User user = await _context.Users.FirstOrDefaultAsync(u => u.Email == model.Email);

                if (user == null)
                {
                                        _context.Users.Add(new User {
                        Email = model.Email, Password = model.Password
                    });
                    await _context.SaveChangesAsync();

                    await Authenticate(model.Email);

                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ModelState.AddModelError("", "Email already Exists");
                }
            }
            return(View(model));
        }