public ActionResult EditCustomer(int id)
        {
            LibraryManagementSystemContext context             = new LibraryManagementSystemContext();
            CustomersRepository            customersRepository = new CustomersRepository(context);
            CustomersEditCustomerVM        model = new CustomersEditCustomerVM();

            Customer customer = customersRepository.GetByID(id);

            if (id > 0)
            {
                model.ID             = customer.ID;
                model.PersonalNumber = customer.PersonalNumber;
                model.FirstName      = customer.FirstName;
                model.LastName       = customer.LastName;
                model.Email          = customer.Email;
                model.Address        = customer.Address;
                model.PicturePath    = customer.PicturePath;
                model.Birthday       = customer.Birthday;
                model.DateIn         = customer.DateIn;
                if (customer.DateOut != null)
                {
                    model.DateOut = customer.DateOut.Value;
                }
            }
            else
            {
                customer      = new Customer();
                model.DateOut = null;
            }

            return(View(model));
        }
        public ActionResult EditCustomer(CustomersEditCustomerVM model)
        {
            LibraryManagementSystemContext context             = new LibraryManagementSystemContext();
            CustomersRepository            customersRepository = new CustomersRepository(context);

            ModelState.Remove("DateOut");

            if (model.Email != null && customersRepository.GetAll().Any(c => c.Email == model.Email) &&
                model.ID != customersRepository.GetAll(filter: c => c.Email == model.Email).FirstOrDefault().ID)
            {
                ModelState.AddModelError("Email", "* email already exists");
            }
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            else
            {
                Customer customer = null;
                if (model.ID > 0)
                {
                    customer = customersRepository.GetByID(model.ID);
                    customer.PersonalNumber = model.PersonalNumber;
                }
                else
                {
                    customer = new Customer();
                    customer.PersonalNumber = customersRepository.GetAll().LastOrDefault().PersonalNumber + 1;
                }

                customer.ID        = model.ID;
                customer.FirstName = model.FirstName;
                customer.LastName  = model.LastName;
                customer.Email     = model.Email;
                customer.Address   = model.Address;
                customer.Birthday  = model.Birthday;
                customer.DateIn    = model.DateIn;
                customer.DateOut   = model.DateOut != null ? model.DateOut : null;

                customersRepository.Save(customer);
            }

            return(RedirectToAction("Index", "Customers"));
        }