public IResult <Movie> Insert(Movie movie) { if (movie == null) { var e = new ObjectRequiredIsNullException("Movie is required"); return(new Error <Movie>(e)); } if (movie.MovieId == null) { var e = new FieldRequiredIsNullException("Id is null."); return(new Error <Movie>(e)); } if (movie.Title == null) { var e = new FieldRequiredIsNullException("Title is null."); return(new Error <Movie>(e)); } try { context.Movies.Add(movie); context.SaveChanges(); return(new OK <Movie>(movie)); } catch { var e = new DatabaseContextException("Database context error."); return(new Error <Movie>(e)); } }
public IResult <Movie> Update(Movie movie) { if (movie == null) { var e = new ObjectRequiredIsNullException("Movie is required."); return(new Error <Movie>(e)); } if (movie.Title == null) { var e = new FieldRequiredIsNullException("Field is null"); return(new Error <Movie>(e)); } try { var result = context.Movies.Update(movie); context.SaveChanges(); return(new OK <Movie>(result.Entity)); } catch { var e = new DatabaseContextException(); return(new Error <Movie>(e)); } }
public IResult <Movie> GetById(string id) { IResult <Movie> result = moviesRepository.GetById(id); switch (result) { // Daca reusesc, returnez ok. case OK <Movie> ok: return(ok); // Daca nu reusesc din cauza bazei de date. case Error <Movie> error: Exception databaseContextException = new DatabaseContextException("GetById-method repository exception.", error.Exception); return(new Error <Movie>(databaseContextException)); default: Exception getByIdRepoException = new RepositoryUnknownException("GetById-method repository exception."); return(new Error <Movie>(getByIdRepoException)); } }