Ejemplo n.º 1
0
        public async Task <IActionResult> Create([Bind("Id,Name,Description,Image,Price,Category,Contractor,Remaining,Status,Saledate")] Product product)
        {
            if (ModelState.IsValid)
            {
                _context.Add(product);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(product));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("Id,Cid,Time")] Order order)
        {
            if (ModelState.IsValid)
            {
                _context.Add(order);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(order));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Create([Bind("Id,Name,Description")] Category category)
        {
            if (ModelState.IsValid)
            {
                _context.Add(category);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Order(OrderModel model)
        {
            User   user       = _context.User.FirstOrDefault(u => u.Login == User.Identity.Name);
            Order  order      = null;
            Cart   cart_order = null;
            string cart_json  = "";
            float  sum        = 0;

            if (Request.Cookies.ContainsKey("cart"))
            {
                cart_json  = Request.Cookies["cart"];
                cart_order = JsonConvert.DeserializeObject <Cart>(cart_json);
            }
            foreach (Item value in cart_order.items)
            {
                sum = value.cost + sum;
            }
            order             = new Order();
            order.items       = cart_json;
            order.timestamp   = DateTime.Now.ToUniversalTime().ToString();
            order.description = model.description;
            order.cost        = sum;
            _context.Orders.Add(order);
            await _context.SaveChangesAsync();

            order = _context.Orders.FirstOrDefault(u => u.user_id == user.UserId);
            return(RedirectToAction("Shop", "Index"));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                User user = await _context.User.FirstOrDefaultAsync(u => u.Login == model.login);

                if (user == null)
                {
                    user = new User {
                        Login = model.login, Password = await SHA.GenerateSHA256String(model.password + model.login), addres = model.addres
                    };
                    Role userRole = await _context.Roles.FirstOrDefaultAsync(r => r.Name == "User");

                    if (userRole != null)
                    {
                        user.Role = userRole;
                    }

                    _context.User.Add(user);
                    await _context.SaveChangesAsync();

                    await Authenticate(user);

                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ModelState.AddModelError("", "Некорректные логин и(или) пароль");
                }
            }
            return(View(model));
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Add(AddItemModel model)
        {
            if (ModelState.IsValid)
            {
                Item item = new Item {
                    name = model.name, description = model.description, type_item = model.type_item, is_avalible = model.is_avalible, cost = model.cost, image = model.image
                };
                await _context.Items.AddAsync(item);

                await _context.SaveChangesAsync();

                return(RedirectToAction("Index", "Home"));
            }
            return(View(model));
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> Index(string site, string organisation)
        {
            User user = null;
            API  api  = null;

            user = await _context.User.FirstOrDefaultAsync(u => u.Login == User.Identity.Name);



            api = new API
            {
                is_active    = true,
                site         = site,
                organisation = organisation,
                timestamp    = DateTime.Now.ToString(),
                token        = await SHA.GenerateSHA256String(site + organisation + DateTime.Now.ToString())
            };
            await _context.Api.AddAsync(api);

            await _context.SaveChangesAsync();

            return(Content("Token: " + api.token));
        }