public async Task <IActionResult> Edit(int id, [Bind("UserId,Username,Family,Name,Mobile,IsAdmin")] User user, string password, string oldPassword)
        {
            if (id != user.UserId)
            {
                return(NotFound());
            }

            try
            {
                if (password != null && password.Length > 0)
                {
                    user.Password = _hashHelper.GetMD5(password);
                }
                else
                {
                    user.Password = oldPassword;
                }
                _context.Update(user);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserExists(user.UserId))
                {
                    return(NotFound());
                }
                else
                {
                }
            }

            return(View(user));
        }
Пример #2
0
        public async Task <IActionResult> Edit(int id, [Bind("CityId,StateId,Name")] City city)
        {
            if (id != city.CityId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(city);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CityExists(city.CityId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["StateId"] = new SelectList(_context.State, "StateId", "Name", city.StateId);
            return(View(city));
        }
        public async Task <IActionResult> Edit(int id, [Bind("SubcategoryId,CategoryId,Name")] Subcategory subcategory)
        {
            if (id != subcategory.SubcategoryId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(subcategory);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SubcategoryExists(subcategory.SubcategoryId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoryId"] = new SelectList(_context.Category, "CategoryId", "Name", subcategory.CategoryId);
            return(View(subcategory));
        }
        public async Task <IActionResult> Edit(int id, [Bind("UnitId,Name")] Unit unit)
        {
            if (id != unit.UnitId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(unit);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UnitExists(unit.UnitId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(unit));
        }
        public async Task <IActionResult> Edit(int id, [Bind("ProductAttributeId,Name,UnitId")] ProductAttribute productAttribute)
        {
            if (id != productAttribute.ProductAttributeId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(productAttribute);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProductAttributeExists(productAttribute.ProductAttributeId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["UnitId"] = new SelectList(_context.Unit, "UnitId", "Name", productAttribute.UnitId);
            return(View(productAttribute));
        }
        public async Task <IActionResult> Edit(int id, [Bind("ProductId,SubcategoryId,Name,UnitPrice,PhotoFilename")] Product product, IFormFile photoFile)
        {
            if (id != product.ProductId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    if (photoFile != null)
                    {
                        string       photoFilename = $"{Guid.NewGuid().ToString()}.jpg";
                        MemoryStream stream        = new MemoryStream();
                        photoFile.CopyTo(stream);
                        new ImageFactory().Load(stream.GetBuffer())
                        .Resize(new Size(800, 0))
                        .Format(new JpegFormat())
                        .Save($"{_hostEnvironment.ContentRootPath}\\wwwroot\\files\\productphotos\\{photoFilename}");
                        product.PhotoFilename = photoFilename;
                    }
                    _context.Update(product);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProductExists(product.ProductId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["SubcategoryId"] = new SelectList(_context.Subcategory, "SubcategoryId", "Name", product.SubcategoryId);
            return(View(product));
        }