// GET: Admin/AppSettings/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                Response.StatusCode = 404;
                return(View("AppSettingsNotFound"));
            }

            var appSetting = await _context.AppSettings.FindAsync(id);

            if (appSetting == null)
            {
                Response.StatusCode = 404;
                return(View("AppSettingsNotFound"));
            }
            var appSettingEdit = new AppSettingEditModelView()
            {
                AmountExternalCreditToTrip = appSetting.AmountExternalCreditToTrip,
                Stamp       = appSetting.Stamp,
                Id          = appSetting.Id,
                BookingTime = appSetting.BookingTime,
                AmountInternalCreditToTrip = appSetting.AmountInternalCreditToTrip,
                AmountOmrahCreditToTrip    = appSetting.AmountOmrahCreditToTrip,
                AmountVisitCreditToTrip    = appSetting.AmountVisitCreditToTrip,
                QtyCollegesDelegates       = appSetting.QtyCollegesDelegates,
                QtyDeanshipDelegates       = appSetting.QtyDeanshipDelegates,
                QtyExternalDaysTrip        = appSetting.QtyExternalDaysTrip,
                QtyInstitutesDelegates     = appSetting.QtyInstitutesDelegates,
                QtyInternalDaysTrip        = appSetting.QtyInternalDaysTrip,
                QtyOmrahMakkahDaysTrip     = appSetting.QtyOmrahMakkahDaysTrip,
                QtyOmrahMedinaDaysTrip     = appSetting.QtyOmrahMedinaDaysTrip,
                QtyPassengersInOneBus      = appSetting.QtyPassengersInOneBus,
                QtyExtirnalBuses           = appSetting.QtyExtirnalBuses,
                QtyVisitExtirnalBuses      = appSetting.QtyVisitExtirnalBuses,
                QtyVisitIntirnalBuses      = appSetting.QtyVisitIntirnalBuses,
                QtyIntirnalBuses           = appSetting.QtyIntirnalBuses,
                QtyUmrahBuses        = appSetting.QtyUmrahBuses,
                QtyDaysVisitEternal  = appSetting.QtyDaysVisitEternal,
                QtyDaysVisitInternal = appSetting.QtyDaysVisitInternal
            };

            return(View(appSettingEdit));
        }
        public async Task <IActionResult> Edit(int id, AppSettingEditModelView appSetting)
        {
            if (id != appSetting.Id)
            {
                Response.StatusCode = 404;
                return(View("AppSettingsNotFound"));
            }

            if (ModelState.IsValid)
            {
                string filenameForEdit = null;
                string uniqFileName    = null;
                if (appSetting.StampFile != null && appSetting.StampFile.Length > 0)
                {
                    string filePathForDelete = Path.Combine(_ihostingEnvironment.WebRootPath,
                                                            "img/stamps", appSetting.Stamp);
                    System.IO.File.Delete(filePathForDelete);
                    if (IsFileValidate(appSetting.StampFile.FileName))
                    {
                        string uplouadsFolder = Path.Combine(_ihostingEnvironment.WebRootPath, "img/stamps");
                        uniqFileName = Guid.NewGuid().ToString() + "_" + appSetting.StampFile.FileName;
                        string filePath = Path.Combine(uplouadsFolder, uniqFileName);

                        using (var fileStream = new FileStream(filePath, FileMode.Create))
                        {
                            appSetting.StampFile.CopyTo(fileStream);
                        }
                    }
                    else
                    {
                        ViewBag.msg = "الصور المسموح بها يجب ان تكون بمتداد : " + "png , jpeg , jpg , gif , bmp ";

                        return(View(appSetting));
                    }
                }
                filenameForEdit = uniqFileName == null ? appSetting.Stamp : uniqFileName;
                var settengUpdate = new AppSetting()
                {
                    AmountExternalCreditToTrip = appSetting.AmountExternalCreditToTrip,
                    Stamp       = filenameForEdit, Id = appSetting.Id,
                    BookingTime = appSetting.BookingTime,
                    AmountInternalCreditToTrip = appSetting.AmountInternalCreditToTrip,
                    AmountOmrahCreditToTrip    = appSetting.AmountOmrahCreditToTrip,
                    AmountVisitCreditToTrip    = appSetting.AmountVisitCreditToTrip,
                    QtyCollegesDelegates       = appSetting.QtyCollegesDelegates,
                    QtyDeanshipDelegates       = appSetting.QtyDeanshipDelegates,
                    QtyExternalDaysTrip        = appSetting.QtyExternalDaysTrip,
                    QtyInstitutesDelegates     = appSetting.QtyInstitutesDelegates,
                    QtyInternalDaysTrip        = appSetting.QtyInternalDaysTrip,
                    QtyOmrahMakkahDaysTrip     = appSetting.QtyOmrahMakkahDaysTrip,
                    QtyOmrahMedinaDaysTrip     = appSetting.QtyOmrahMedinaDaysTrip,
                    QtyPassengersInOneBus      = appSetting.QtyPassengersInOneBus,
                    QtyExtirnalBuses           = appSetting.QtyExtirnalBuses,
                    QtyVisitExtirnalBuses      = appSetting.QtyVisitExtirnalBuses,
                    QtyVisitIntirnalBuses      = appSetting.QtyVisitIntirnalBuses,
                    QtyIntirnalBuses           = appSetting.QtyIntirnalBuses,
                    QtyUmrahBuses        = appSetting.QtyUmrahBuses,
                    QtyDaysVisitEternal  = appSetting.QtyDaysVisitEternal,
                    QtyDaysVisitInternal = appSetting.QtyDaysVisitInternal
                };
                _context.Update(settengUpdate);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(appSetting));
        }