Beispiel #1
0
        public HttpResponseMessage UpdateProducer([FromUri] string producerId, [FromBody] producer pr)
        {
            producer prod           = null;
            Guid     producerIdGuid = new Guid(producerId);

            using (movieBucketEntities entity = new movieBucketEntities())
            {
                try
                {
                    prod = entity.producers.Where(m => m.producer_id == producerIdGuid).FirstOrDefault();
                    if (prod == null)
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Producer Detail not found In Database, Please Add new Detail !!!"));
                    }
                    prod.bio           = pr.bio;
                    prod.date_of_birth = pr.date_of_birth;
                    prod.name          = pr.name;
                    prod.sex           = pr.sex;
                    prod.Movies        = pr.Movies;
                    entity.SaveChanges();
                }
                catch (Exception e)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e.Message));
                }
                return(Request.CreateResponse(HttpStatusCode.OK, prod));
            }
        }
        public HttpResponseMessage addMovie(Movie movie)
        {
            Movie mov     = new Movie();
            Guid  movieId = Guid.NewGuid();

            using (movieBucketEntities entity = new movieBucketEntities())
            {
                mov.movie_id        = movieId;
                mov.movie_name      = movie.movie_name;
                mov.plot            = movie.plot;
                mov.producer_id     = movie.producer_id;
                mov.year_of_release = movie.year_of_release;
                //mov.Actors.Add(movie.Actors.First());
                mov.poster = movie.poster;
                try
                {
                    entity.Movies.Add(mov);
                    foreach (var act in movie.Actors)
                    {
                        var actorDetail = entity.Actors.Where(m => m.actor_Id == act.actor_Id).FirstOrDefault();
                        actorDetail.Movies.Add(mov);
                    }
                    //entity.Movies.Attach(mov);
                    entity.SaveChanges();
                }
                catch (Exception e)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e.Message));
                }
                return(Request.CreateResponse(HttpStatusCode.Accepted));
            }
        }
        public HttpResponseMessage UpdateActor([FromUri] string actorId, [FromBody] Actor actor)
        {
            string exceptionString = null;
            Guid   actorIdGuid     = new Guid(actorId);

            using (movieBucketEntities entity = new movieBucketEntities())
            {
                try
                {
                    Actor actorData = entity.Actors.Where(m => m.actor_Id == actorIdGuid).FirstOrDefault();
                    if (actorData == null)
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Actor Detail Not found in Database, Please Add detail!!!"));
                    }
                    actorData.bio           = actor.bio;
                    actorData.date_of_birth = actor.date_of_birth;
                    actorData.name          = actor.name;
                    actorData.sex           = actor.sex;
                    entity.SaveChanges();
                    return(Request.CreateResponse(HttpStatusCode.OK, actor));
                }
                catch (Exception e)
                {
                    exceptionString = e.Message;
                    return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exceptionString));
                }
            }
        }
Beispiel #4
0
 public IEnumerable <producer> GetAllProducer()
 {
     using (movieBucketEntities entity = new movieBucketEntities())
     {
         entity.Configuration.ProxyCreationEnabled = false;
         return(entity.producers.ToList());
     }
 }
        public HttpResponseMessage GetActor(string actorId)
        {
            Guid actorIdGuid           = new Guid(actorId);
            movieBucketEntities entity = new movieBucketEntities();
            var actor = entity.Actors.Where(m => m.actor_Id == actorIdGuid).FirstOrDefault();

            if (actor != null)
            {
                return(Request.CreateResponse(HttpStatusCode.OK, actor));
            }
            return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Actor detail Not Found"));
        }
 public HttpResponseMessage UpdateMovie([FromUri] Guid movieId, [FromBody] Movie mov)
 {
     try
     {
         using (movieBucketEntities entity = new movieBucketEntities())
         {
             var data = entity.Movies.Where(m => m.movie_id == movieId).FirstOrDefault();
             if (data == null)
             {
                 return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Movie does not Exist in Database"));
             }
             data.movie_name      = mov.movie_name;
             data.plot            = mov.plot;
             data.poster          = mov.poster;
             data.year_of_release = mov.year_of_release;
             if (data.producer_id != mov.producer_id)
             {
                 var prodData = entity.producers.Where(m => m.producer_id == data.producer_id).FirstOrDefault();
                 prodData.Movies.Remove(mov);
                 data.producer_id = mov.producer_id;
             }
             foreach (var act in mov.Actors)
             {
                 var actorDetail = entity.Actors.Where(m => m.actor_Id == act.actor_Id).FirstOrDefault();
                 if (actorDetail.Movies.Where(m => m.movie_id == mov.movie_id).Count() == 0)
                 {
                     data.Actors.Add(actorDetail);
                 }
             }
             List <Actor> actorList = new List <Actor>();
             foreach (var act in data.Actors)
             {
                 actorList.Add(act);
             }
             foreach (var act in actorList)
             {
                 if (mov.Actors.Where(m => m.actor_Id == act.actor_Id).Count() == 0)
                 {
                     var actorDetail = entity.Actors.Where(m => m.actor_Id == act.actor_Id).FirstOrDefault();
                     actorDetail.Movies.Remove(mov);
                     data.Actors.Remove(act);
                 }
             }
             entity.SaveChanges();
             return(Request.CreateResponse(HttpStatusCode.OK));
         }
     }catch (Exception e)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e.Message));
     }
 }
Beispiel #7
0
 public HttpResponseMessage PutProducer([FromBody] producer prod)
 {
     prod.producer_id = Guid.NewGuid();
     using (movieBucketEntities entity = new movieBucketEntities())
     {
         try
         {
             entity.producers.Add(prod);
             entity.SaveChanges();
         }
         catch (Exception e)
         {
             return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e.Message));
         }
         return(Request.CreateResponse(HttpStatusCode.Accepted));
     }
 }
        public HttpResponseMessage DeleteActor(string actorId)
        {
            Guid actorIdGuid = new Guid(actorId);

            using (movieBucketEntities entity = new movieBucketEntities())
            {
                try
                {
                    entity.Actors.Remove(entity.Actors.Where(m => m.actor_Id == actorIdGuid).FirstOrDefault());
                }
                catch (Exception e)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e.Message));
                }
                return(Request.CreateResponse(HttpStatusCode.OK));
            }
        }
Beispiel #9
0
        public HttpResponseMessage DeleteProducer([FromUri] string producerId)
        {
            Guid producerIdGuid = new Guid(producerId);

            using (movieBucketEntities entity = new movieBucketEntities())
            {
                try
                {
                    var producer = entity.producers.Where(m => m.producer_id == producerIdGuid).FirstOrDefault();
                    entity.producers.Remove(producer);
                    entity.SaveChanges();
                }
                catch (Exception e)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e.Message));
                }
                return(Request.CreateResponse(HttpStatusCode.OK));
            }
        }
Beispiel #10
0
        public HttpResponseMessage GetProducer(string producerId)
        {
            producer prod           = null;
            Guid     producerIdGuid = new Guid(producerId);

            using (movieBucketEntities entity = new movieBucketEntities())
            {
                try
                {
                    prod = entity.producers.Where(m => m.producer_id == producerIdGuid).FirstOrDefault();
                    if (prod == null)
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Producer data not available"));
                    }
                }
                catch (Exception e)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e.Message));
                }
                return(Request.CreateResponse(HttpStatusCode.OK, prod));
            }
        }
        public HttpResponseMessage DeleteMovie(string movieId)
        {
            Guid movieIdGuid = new Guid(movieId);

            using (movieBucketEntities entity = new movieBucketEntities())
            {
                try
                {
                    var data = entity.Movies.Where(m => m.movie_id == movieIdGuid).FirstOrDefault();
                    foreach (var actor in data.Actors)
                    {
                        var actorData = entity.Actors.Where(m => m.actor_Id == actor.actor_Id).FirstOrDefault();
                        actorData.Movies.Remove(data);
                    }
                    entity.Movies.Remove(data);
                    entity.SaveChanges();
                }
                catch (Exception e)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e.Message));
                }
                return(Request.CreateResponse(HttpStatusCode.OK));
            }
        }
        public HttpResponseMessage PutActor([FromBody] Actor actor)
        {
            Guid actorId = Guid.NewGuid();

            using (movieBucketEntities entity = new movieBucketEntities())
            {
                try
                {
                    actor.actor_Id = actorId;
                    var res = entity.Actors.Add(actor);
                    if (res == null)
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "No Data Updated"));
                    }
                    entity.SaveChanges();
                }
                catch (Exception e)
                {
                    string exceptionMessage = e.Message;
                    return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exceptionMessage));
                }
                return(Request.CreateResponse(HttpStatusCode.OK));
            }
        }
        public IEnumerable <Movie> GetAllMovies()
        {
            movieBucketEntities entity = new movieBucketEntities();

            return(entity.Movies.AsEnumerable());
        }