public IActionResult Index()
        {
            var viewModel = new TrainersViewModel()
            {
                Trainers = _dataManager.Trainers.GetTrainers().ToList()
            };

            return(View(viewModel));
        }
        private TrainersViewModel GetTrainersViewModel()
        {
            TrainersViewModel TrainersViewModel = new TrainersViewModel()
            {
                RegDate  = DateTime.Now,
                Trainers = _trainers.Entity.GetAll().AsNoTracking().ToList(),
            };

            return(TrainersViewModel);
        }
        public async Task <ActionResult> Create(TrainersViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    if (model.File == null)
                    {
                        ViewBag.Message = "Please select image";
                        return(View(GetTrainersViewModel()));
                    }
                    var FName = await _trainers.Entity.GetAll().Where(a => a.Name.ToUpper() == model.Name.ToUpper()).FirstOrDefaultAsync();

                    if (FName != null)
                    {
                        ViewBag.Message = "The Name Of a Trainers is Registerd";
                        return(View(GetTrainersViewModel()));
                    }
                    if (model.File.Length > 0)
                    {
                        if (!CheckImgExtension(model.File))
                        {
                            ViewBag.Message = "The attached file is not an image file";
                            return(View(GetTrainersViewModel()));
                        }

                        Trainers trainer = new Trainers
                        {
                            RegDate        = model.RegDate,
                            CreatedDate    = DateTime.Now,
                            Name           = model.Name,
                            Specialization = model.Specialization,
                            DataFile       = FileToByte(model.File),
                        };
                        _trainers.Entity.Insert(trainer);
                        await _trainers.SaveAsync();

                        return(RedirectToAction("Details", new { id = trainer.Id }));
                    }
                }
                catch (Exception)
                {
                    throw;
                }
            }
            return(View(GetTrainersViewModel()));
        }
        public async Task <IActionResult> Edit(TrainersViewModel model, string hidden1)
        {
            string test1 = hidden1;


            if (ModelState.IsValid)
            {
                try
                {
                    Trainers trainers = new Trainers();
                    trainers.Id             = model.Id;
                    trainers.CreatedDate    = model.CreatedDate;
                    trainers.Name           = model.Name;
                    trainers.Email          = model.Email;
                    trainers.Facebook       = model.Facebook;
                    trainers.Specialization = model.Specialization;
                    trainers.RegDate        = model.RegDate;
                    trainers.ModifiedDate   = DateTime.Now;
                    if (model.File != null)
                    {
                        if (!CheckImgExtension(model.File))
                        {
                            ViewBag.Message = "The attached file is not an image file";
                            return(View(model));
                        }
                        trainers.DataFile = FileToByte(model.File);
                    }
                    else
                    {
                        trainers.DataFile = model.DataFile;     //يأخذ الصورة القديمة التي تم تخزينها في hidden
                    }

                    _trainers.Entity.Update(trainers);
                    await _trainers.SaveAsync();
                }
                catch
                {
                    throw;
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(model));
        }
        public async Task <IActionResult> Edit(Guid Id)
        {
            var trainers = await _trainers.Entity.GetByIdAsync(Id);

            if (trainers == null)
            {
                return(View("NotFound"));
            }

            TrainersViewModel TrainersViewModel = new TrainersViewModel
            {
                Id             = trainers.Id,
                CreatedDate    = trainers.CreatedDate,
                Specialization = trainers.Specialization,
                Name           = trainers.Name,
                Facebook       = trainers.Facebook,
                Email          = trainers.Email,
                RegDate        = trainers.RegDate,
                DataFile       = trainers.DataFile,
            };

            return(View(TrainersViewModel));
        }