public IActionResult Edit(int id, Defect defect)
        {
            if (id != defect.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    foreach (Photo photo in defect.Photos)
                    {
                        if (photo.Id == 0)
                        {
                            photo.Path          = SaveFile(photo.PhotoFile);
                            photo.DefectId      = id;
                            photo.NewlyInserted = true;
                            photo.Id            = photosRepository.Create(photo);
                        }
                    }
                    defectsRepository.Update(id, defect);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!DefectExists(defect.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            return(View(defect));
        }