Пример #1
0
        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));
            }
        }
Пример #2
0
        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));
            }
        }