public async Task <IActionResult> Add(Employee employee, string NameImage, string NameFolder)
        {
            var info = HttpContext.Session.GetObject <Employee>("Employee");

            if (info == null)
            {
                return(BadRequest(new { message = "login" }));
            }
            if (ModelState.IsValid && employee != null)
            {
                bool check = _context.Employee.Any(e => e.UserName == employee.UserName);
                if (!check)
                {
                    MyTool.MoveImage("Employee", NameImage, NameFolder);
                    employee.Image       = NameImage;
                    employee.CreatedDate = DateTime.Now;
                    employee.Password    = MyHashTool.GetMd5Hash(employee.Password);

                    _context.Employee.Add(employee);
                    await _context.SaveChangesAsync();
                }
                else
                {
                    return(BadRequest(new { content = "Tài khoản đã tồn tại!!!" }));
                }
            }
            else
            {
                return(BadRequest(new { content = "Vui lòng điền thông tin tài khoản!" }));
            }

            var model = await _context.Employee.AsNoTracking().ToListAsync();

            return(View("Datatable", model));
        }
        public async Task <IActionResult> Edit(Customer customer, string NameImage, string NameFolder)
        {
            var info = HttpContext.Session.GetObject <Employee>("Employee");

            if (info == null)
            {
                return(BadRequest(new { message = "login" }));
            }
            MyTool.MoveImage("Customer", NameImage, NameFolder);

            var cus = await _context.Customer.AsNoTracking().SingleOrDefaultAsync(e => e.CustomerId == customer.CustomerId);

            if (customer.Password != cus.Password)
            {
                customer.Password = MyHashTool.GetMd5Hash(customer.Password);
            }

            if (ModelState.IsValid)
            {
                try
                {
                    customer.Image = NameImage;
                    _context.Update(customer);
                    await _context.SaveChangesAsync();
                }
                catch
                {
                    return(BadRequest(new { content = "Sửa không thành công!!!" }));
                }
                var model = await _context.Customer.AsNoTracking().ToListAsync();

                return(View("Datatable", model));
            }
            return(View(customer));
        }
        public async Task <IActionResult> Edit([Bind("EmployeeId,UserName,Password,FirstName,LastName,Address,Email,Sex,Phone,BirthDate,Role,ManagerId,Image,IsActive")] Employee employee, string NameImage, string NameFolder)
        {
            var info = HttpContext.Session.GetObject <Employee>("Employee");

            if (info == null)
            {
                return(BadRequest(new { message = "login" }));
            }


            if (ModelState.IsValid)
            {
                try
                {
                    var emp = await _context.Employee.AsNoTracking().SingleOrDefaultAsync(e => e.EmployeeId == employee.EmployeeId);

                    if (emp == null)
                    {
                        return(BadRequest(new { content = "Không tồn tại nhân viên này!!" }));
                    }
                    if (employee.Password != emp.Password)
                    {
                        employee.Password = MyHashTool.GetMd5Hash(employee.Password);
                    }
                    MyTool.MoveImage("Employee", NameImage, NameFolder);
                    employee.Image = NameImage;

                    employee.UserName = emp.UserName;
                    _context.Update(employee);
                    await _context.SaveChangesAsync();
                }
                catch
                {
                    return(BadRequest(new { content = "Sửa không thành công!" }));
                }
            }

            var model = await _context.Employee.AsNoTracking().ToListAsync();

            return(View("Datatable", model));
        }
        public async Task <IActionResult> Add(Customer customer, string NameImage, string NameFolder)
        {
            var info = HttpContext.Session.GetObject <Employee>("Employee");

            if (info == null)
            {
                return(BadRequest(new { message = "login" }));
            }
            if (ModelState.IsValid && customer != null)
            {
                bool check = _context.Customer.Any(c => c.UserName == customer.UserName);
                if (!check)
                {
                    MyTool.MoveImage("Customer", NameImage, NameFolder);
                    Customer cus = _context.Customer.SingleOrDefault(c => c.CustomerId == customer.CustomerId);
                    customer.Image       = NameImage;
                    customer.CreatedDate = DateTime.Now;
                    if (cus.Password != customer.Password)
                    {
                        customer.Password = MyHashTool.GetMd5Hash(customer.Password);
                    }
                    _context.Customer.Add(customer);
                    await _context.SaveChangesAsync();
                }
                else
                {
                    return(BadRequest(new { content = "Tài khoản này đã tồn tại!!!" }));
                }
            }
            else
            {
                return(BadRequest());
            }

            var model = await _context.Customer.AsNoTracking().ToListAsync();

            return(View("Datatable", model));
        }