public async Task <IActionResult> Create([Bind("Upload,Photo,Id")] AppointmentPhoto appointmentPhoto)
        {
            if (appointmentPhoto.Upload == null)
            {
                ModelState.AddModelError("Upload", "Şəkil məcburidir");
            }
            else
            {
                if (appointmentPhoto.Upload.ContentType != "image/jpeg" && appointmentPhoto.Upload.ContentType != "image/png" && appointmentPhoto.Upload.ContentType != "image/gif")
                {
                    ModelState.AddModelError("Upload", "Siz yalnız png,jpg və ya gif faylı yükləyə bilərsiniz");
                }

                if (appointmentPhoto.Upload.Length > 1048576)
                {
                    ModelState.AddModelError("Upload", "Fayl ölcüsu maximum 1MB ola bilər");
                }
            }
            if (ModelState.IsValid)
            {
                var fileName = _fileManager.Upload(appointmentPhoto.Upload);
                appointmentPhoto.Photo = fileName;

                _context.Add(appointmentPhoto);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(appointmentPhoto));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Upload,Photo,Id")] AppointmentPhoto appointmentPhoto)
        {
            if (id != appointmentPhoto.Id)
            {
                return(NotFound());
            }

            if (appointmentPhoto.Upload == null)
            {
                ModelState.AddModelError("Upload", "Şəkil məcburidir");
            }

            if (ModelState.IsValid)
            {
                try
                {
                    if (appointmentPhoto.Upload != null)
                    {
                        if (appointmentPhoto.Upload.ContentType != "image/jpeg" && appointmentPhoto.Upload.ContentType != "image/png" && appointmentPhoto.Upload.ContentType != "image/gif")
                        {
                            ModelState.AddModelError("Upload", "Siz yalnız png,jpg və ya gif faylı yükləyə bilərsiniz");
                            return(View(appointmentPhoto));
                        }


                        if (appointmentPhoto.Upload.Length > 1048576)
                        {
                            ModelState.AddModelError("Upload", "Fayl ölcüsu maximum 1MB ola bilər");
                            return(View(appointmentPhoto));
                        }

                        var oldFile = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "uploads", appointmentPhoto.Photo);
                        _fileManager.Delete(oldFile);

                        var fileName = _fileManager.Upload(appointmentPhoto.Upload, "wwwroot/uploads");
                        appointmentPhoto.Photo = fileName;
                    }

                    _context.Update(appointmentPhoto);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AppointmentPhotoExsist(appointmentPhoto.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(appointmentPhoto));
        }