Exemplo n.º 1
0
        public async Task <IActionResult> PutCart(Guid id, Cart cart)
        {
            if (id != cart.Id)
            {
                return(BadRequest());
            }

            _context.Entry(cart).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CartExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("PhoneNumber,VerificationCode,FullName,NotificationDeviceId,Id,CreationDate,DeletedDate")] User user)
        {
            if (ModelState.IsValid)
            {
                user.Id = Guid.NewGuid();
                _context.Add(user);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(user));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Create([Bind("IsPayed,PaymentUrl,DeliveryAddress,OrderStatus,Id,CreationDate,DeletedDate")] Order order)
        {
            if (ModelState.IsValid)
            {
                order.Id = Guid.NewGuid();
                _context.Add(order);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(order));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Create([Bind("Name,ImageUrl,Id,CreationDate,DeletedDate")] Category category)
        {
            if (ModelState.IsValid)
            {
                category.Id = Guid.NewGuid();
                _context.Add(category);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }
Exemplo n.º 5
0
        public async Task SaveCodeToUser(string phoneNumber, string code)
        {
            var user = await context.Users.FirstOrDefaultAsync(user => user.PhoneNumber == phoneNumber);

            if (user is null)
            {
                user = new User
                {
                    PhoneNumber      = phoneNumber,
                    VerificationCode = code,
                    Cart             = new Cart(),
                    FullName         = "User-" + Guid.NewGuid().ToString(),
                    FavoriteProducts = new List <FavoriteProduct>()
                };

                await context.Users.AddAsync(user);
            }
            else
            {
                user.VerificationCode = code;
            }

            await context.SaveChangesAsync();
        }