public bool WriteHeaderDescription(EditFileInfo editFileInfo) { string searchString = string.Empty; if (string.IsNullOrEmpty(editFileInfo.Path)) { searchString = editFileInfo.FileName; } else { searchString = Path.Combine(editFileInfo.Path, editFileInfo.FileName); } using (FamilyArchiveContext db = new FamilyArchiveContext()) { Photos photo = db.Photos.Where(p => p.Name == searchString).FirstOrDefault(); if (photo != null) { photo.Header = editFileInfo.NewHeader; photo.Description = editFileInfo.NewDescription; db.SaveChanges(); return(true); } else { return(false); } } }
public IActionResult EditPhoto([FromBody] EditFileInfo editFileInfo) { if (_dbService.WriteHeaderDescription(editFileInfo)) { return(Ok()); } else { return(BadRequest("No record in database. Wait or try to delete and add photo again")); } }