コード例 #1
0
        public async Task <IActionResult> Profile(int id, [Bind("Id,Email,Password,ConfirmPassword,FullName,Gender,Type")] Account account)
        {
            if (id != account.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(account);
                    await _context.SaveChangesAsync();
                }

                catch (DbUpdateConcurrencyException)
                {
                    if (!AccountExists(account.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index", "Main"));
            }
            return(View(account));
        }
コード例 #2
0
        public async Task <IActionResult> AddToCart(int id)
        {
            var userEmail = User.Claims.FirstOrDefault(c => c.Type == "Email")?.Value;

            if (userEmail == null)
            {
                return(RedirectToAction("LoginBeforeShopping", "Account"));
            }
            var query = _context.Cart.Where(s => s.Clothings.Id == id).Where(s => s.account.Email == userEmail).FirstOrDefault <Cart>();

            if (query == null)
            {
                Account   account = _context.Account.First(s => s.Email == userEmail);
                Clothings product = _context.Clothings.First(s => s.Id == id);
                Cart      c       = new Cart {
                    Clothings = product, Count = 1, account = account
                };
                _context.Cart.Add(c);
            }
            else
            {
                query.Count++;
            }

            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
コード例 #3
0
        public async Task <IActionResult> Create([Bind("Id,OrderTime")] Click_Details click_Details)
        {
            if (ModelState.IsValid)
            {
                _context.Add(click_Details);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(click_Details));
        }
コード例 #4
0
        public async Task <IActionResult> Create([Bind("ID,MechanicName,Adress")] Mechanic mechanic)
        {
            if (ModelState.IsValid)
            {
                _context.Add(mechanic);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(mechanic));
        }
コード例 #5
0
        public async Task <IActionResult> Plus(int id)
        {
            var query = _context.Cart.Where(s => s.Id == id).FirstOrDefault <Cart>();

            if (query != null)
            {
                query.Count++;
            }
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
コード例 #6
0
        public async Task <IActionResult> OrderEdit(int id, [Bind("Id,Address,OrderTime,Phone,SumToPay")] Order order)
        {
            if (id != order.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(order);
                    await _context.SaveChangesAsync();
                }
                catch (Exception)
                {
                    if (!OrderExists(order.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(order));
        }
コード例 #7
0
        public async Task <IActionResult> Create([Bind("ID,Brand,Model,Price")] Car car)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(car);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (DbUpdateException /* ex*/)
            {
                ModelState.AddModelError("", "Unable to save changes. " +
                                         "Try again, and if the problem persists ");
            }
            return(View(car));
        }