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));
            }
        }
Esempio n. 2
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 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));
                }
            }
        }
 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));
     }
 }
Esempio n. 5
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));
     }
 }
Esempio n. 6
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));
            }
        }
        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));
            }
        }