public IHttpActionResult UpdateProduction([FromBody] Production production_to_update)
        {
            try
            {
                using (var dbcontext = new BroadwayBuilderContext())
                {
                    var productionService = new ProductionService(dbcontext);

                    if (production_to_update == null)
                    {
                        return(BadRequest("No production object provided"));
                    }
                    else if (production_to_update.ProductionID == 0)
                    {
                        return(BadRequest("Production id was not sent"));
                    }


                    Production updated_production = productionService.UpdateProduction(production_to_update);
                    dbcontext.SaveChanges();

                    return(Ok(updated_production));
                }
            }
            catch (DbUpdateException e)
            {
                return(Content((HttpStatusCode)500, e.Message));
            }
            // Catching all general exceptions and returning to user
            catch (Exception e)  // Todo: Log error
            {
                return(BadRequest(e.Message));
            }
        }
Пример #2
0
        public IHttpActionResult UpdateProduction([FromBody] Production production_to_update)
        {
            using (var dbcontext = new BroadwayBuilderContext())
            {
                var productionService = new ProductionService(dbcontext);

                try
                {
                    if (production_to_update == null)
                    {
                        return(BadRequest("no production object provided"));
                    }
                    else if (production_to_update.ProductionID == null)
                    {
                        return(BadRequest("Production id is null"));
                    }


                    Production updated_production = productionService.UpdateProduction(production_to_update);
                    dbcontext.SaveChanges();

                    return(Ok(updated_production));
                }
                // Hack: Need to add proper exception handling
                catch (Exception e)
                {
                    return(BadRequest());
                }
            }
        }
        public void ProductionService_UpdateProduction_Pass()
        {
            // Arrange
            var dbcontext      = new BroadwayBuilderContext();
            var theaterService = new TheaterService(dbcontext);

            var theater = new Theater("The Magicians", "Regal", "theater st", "LA", "CA", "US", "323323");

            theaterService.CreateTheater(theater);
            dbcontext.SaveChanges();

            var productionService = new ProductionService(dbcontext);

            var productionName    = "The Lion King";
            var directorFirstName = "Joan";
            var directorLastName  = "Doe";
            var street            = "123 Anahiem St";
            var city          = "Long Beach";
            var stateProvince = "California";
            var country       = "United States";
            var zipcode       = "919293";

            var production = new Production(theater.TheaterID, productionName, directorFirstName, directorLastName, street, city, stateProvince, country, zipcode);

            productionService.CreateProduction(production);
            dbcontext.SaveChanges();


            production.ProductionName   = "The Lion King 2";
            production.StateProvince    = "Utah";
            production.DirectorLastName = "Mangos";

            var expected = new List <string>()
            {
                "The Lion King 2",
                "Utah",
                "Mangos"
            };


            // Act
            var actual = productionService.UpdateProduction(production);

            dbcontext.SaveChanges();

            // Assert
            productionService.DeleteProduction(production);
            dbcontext.SaveChanges();
            theaterService.DeleteTheater(theater);
            dbcontext.SaveChanges();
            Assert.AreEqual(expected[0], actual.ProductionName);
            Assert.AreEqual(expected[1], actual.StateProvince);
            Assert.AreEqual(expected[2], actual.DirectorLastName);
        }
Пример #4
0
        public void ProductionService_UpdateProduction_Pass()
        {
            // Arrange
            var dbcontext      = new BroadwayBuilderContext();
            var theaterService = new TheaterService(dbcontext);

            var theater = new Theater()
            {
                TheaterName   = "The Magicians",
                StreetAddress = "Pantene",
                State         = "CA",
                City          = "LA",
                CompanyName   = "123 Sesame St",
                Country       = "US",
                PhoneNumber   = "123456789"
            };

            theaterService.CreateTheater(theater);
            dbcontext.SaveChanges();


            var productionService = new ProductionService(dbcontext);

            var production = new Production()
            {
                ProductionName    = "The Lion King",
                DirectorFirstName = "Jane",
                DirectorLastName  = "Doe",
                Street            = "Anahiem",
                City          = "Long Beach",
                StateProvince = "California",
                Country       = "United States",
                Zipcode       = "919293",
                TheaterID     = theater.TheaterID
            };


            productionService.CreateProduction(production);
            dbcontext.SaveChanges();


            production.ProductionName   = "The Lion King 2";
            production.StateProvince    = "Utah";
            production.DirectorLastName = "Mangos";

            var expected = new List <string>()
            {
                "The Lion King 2",
                "Utah",
                "Mangos"
            };


            // Act
            var actual = productionService.UpdateProduction(production);

            dbcontext.SaveChanges();

            // Assert
            productionService.DeleteProduction(production.ProductionID);
            dbcontext.SaveChanges();
            theaterService.DeleteTheater(theater);
            dbcontext.SaveChanges();
            Assert.AreEqual(expected[0], actual.ProductionName);
            Assert.AreEqual(expected[1], actual.StateProvince);
            Assert.AreEqual(expected[2], actual.DirectorLastName);
        }