Ejemplo n.º 1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Desc,Price,ImgURL")] Product product)
        {
            if (HttpContext.Session.GetString("userName") == null || !HttpContext.Session.GetString("userName").Equals("Admin"))
            {
                return(View("../Products/Index", _context.Product));
            }

            if (id != product.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(product);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProductExists(product.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(product));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,EmailAddress,Passowrd,City,Street")] User user)
        {
            if (HttpContext.Session.GetString("userId") == null)
            {
                return(View("../Products/Index", _context.Product));
            }
            if (id != user.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var userResult = _context.User.Where(u => u.Name == user.Name);
                    if (userResult.Count() > 0 && user.Name != HttpContext.Session.GetString("userName"))
                    {
                        ViewData["Error"] = "שם משתמש קיים במערכת, בחר שם אחר!";
                        return(View(user));
                    }
                    else
                    {
                        _context.Update(user);
                        await _context.SaveChangesAsync();

                        return(View("../Products/Index", _context.Product));
                    }
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UserExists(user.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            return(View(user));
        }