public async Task <IActionResult> Edit(int id, [Bind("FirstName,LastName,Phone,Email,Username,Password,Note,Age,Gender,Address,City,UserType,SubsidiaryTotalProduct,AgentName,SupplyCode,ImageFile,SupplyName,Salary,Id,CreatedDate,ModifiedDate,Avatar")] User user)
        {
            if (id != user.Id)
            {
                return(NotFound());
            }
            if (ModelState.IsValid)
            {
                try
                {
                    user.Avatar = await _commonServices.EditImage(user.ImageFile, user.Avatar, "/images/People");

                    user.ModifiedDate = DateTime.Now.ToUniversalTime();
                    _context.Update(user);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UserExists(user.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(user));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Url,ProductId,Id,CreatedDate,ModifiedDate,ImageFile")] Image image)
        {
            if (id != image.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var product = _context.Products.Find(image.ProductId);
                    image.Url = await _commonServices.EditImage(image.ImageFile, image.Url, "/images/Products/" + product.Name);

                    image.ModifiedDate = DateTime.Now.ToUniversalTime();
                    _context.Update(image);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ImageExists(image.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ProductId"] = new SelectList(_context.Products, "Id", "DisplayName", image.Product.DisplayName);
            return(View(image));
        }
        public async Task UpdateProduct(Product product)
        {
            try
            {
                product.MainImage = await _commonServices.EditImage(product.ImageFile, product.MainImage, "/images/Products/" + product.Name);

                product.MFG          = product.MFG.ToUniversalTime();
                product.EXP          = product.EXP.ToUniversalTime();
                product.RecieveDate  = product.RecieveDate.ToUniversalTime();
                product.ModifiedDate = DateTime.UtcNow;
                await _unitOfWork.Products.Update(product);

                await _unitOfWork.Commit();
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        public async Task <IActionResult> Edit(int id, [Bind("FirstName,LastName,Phone,Email,Username,Password,Note,Age,Gender,Address,City,UserType,SubsidiaryTotalProduct,AgentName,SupplyCode,ImageFile,SupplyName,Salary,Id,CreatedDate,ModifiedDate,Avatar,ExpireContractDate,IsActive,UserType")] User user)
        {
            if (id != user.Id)
            {
                return(NotFound());
            }
            if (ModelState.IsValid)
            {
                try
                {
                    user.Avatar = await _commonServices.EditImage(user.ImageFile, user.Avatar, "/images/People");

                    await _userServices.UpdateSubsidiaryAgent(user);
                }
                catch (DbUpdateConcurrencyException e)
                {
                    throw e;
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(user));
        }