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));
            }
        }
        public IHttpActionResult updateProductionDateTime(int productionDateTimeId, [FromBody] ProductionDateTime productionDateTime)
        {
            try
            {
                using (var dbContext = new BroadwayBuilderContext())
                {
                    var productionService = new ProductionService(dbContext);

                    if (productionDateTime == null)
                    {
                        return(BadRequest("no date time was provided"));
                    }

                    // Set the production date time id that is to be updated to the id in the uri
                    productionDateTime.ProductionDateTimeId = productionDateTimeId;
                    var updatedProductionDateTime = productionService.UpdateProductionDateTime(productionDateTime);
                    dbContext.SaveChanges();

                    return(Ok(updatedProductionDateTime));
                }
            }
            catch (DbUpdateException e)
            {
                return(Content((HttpStatusCode)500, e.Message));
            }

            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
Exemplo n.º 3
0
        public IHttpActionResult deleteProduction(Production productionToDelete)
        {
            using (var dbcontext = new BroadwayBuilderContext())
            {
                var productionService = new ProductionService(dbcontext);

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

                    productionService.DeleteProduction(productionToDelete);
                    dbcontext.SaveChanges();

                    return(Ok("Production deleted succesfully"));
                }
                // Hack: Need to add proper exception handling
                catch (Exception e)
                {
                    return(BadRequest());
                }
            }
        }
        public IHttpActionResult deleteProductiondateTime(int productionDateTimeid, ProductionDateTime productionDateTimeToDelete)
        {
            try
            {
                using (var dbcontext = new BroadwayBuilderContext())
                {
                    var productionService = new ProductionService(dbcontext);

                    if (productionDateTimeToDelete == null)
                    {
                        return(BadRequest("no production date time object provided"));
                    }

                    productionService.DeleteProductionDateTime(productionDateTimeToDelete);
                    dbcontext.SaveChanges();
                    return(Ok("Production date time deleted succesfully!"));
                }
            }
            catch (DbUpdateException e)
            {
                return(Content((HttpStatusCode)500, e.Message));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
Exemplo n.º 5
0
        public List <char> GetallDatesOroductionWithFacid(int facid)
        {
            ProductionService ps = new ProductionService(_Context);
            var res = ps.GetallDatesOroductionWithFacid(facid);

            return(res);
        }
Exemplo n.º 6
0
        public void ProductionService_DeleteProductionThatDoesNotExist_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 Pajama Game 1",
                DirectorFirstName = "Doris",
                DirectorLastName  = "Day",
                City          = "San Diego",
                StateProvince = "California",
                Country       = "U.S",
                TheaterID     = theater.TheaterID,
                Street        = "1234 Sesame St",
                Zipcode       = "91911"
            };

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

            productionService.DeleteProduction(production.ProductionID);
            dbcontext.SaveChanges();

            var expected = true;
            var actual   = false;

            // Act
            try
            {
                productionService.DeleteProduction(production.ProductionID);
            }
            catch (ProductionNotFoundException ex)
            {
                actual = true;
            }

            // Assert
            theaterService.DeleteTheater(theater);
            dbcontext.SaveChanges();
            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 7
0
        public IHttpActionResult deleteProductiondateTime(int productionDateTimeid, ProductionDateTime productionDateTimeToDelete)
        {
            try
            {
                using (var dbcontext = new BroadwayBuilderContext())
                {
                    var productionService = new ProductionService(dbcontext);

                    try
                    {
                        if (productionDateTimeToDelete == null)
                        {
                            return(BadRequest("no production date time object provided"));
                        }

                        productionService.DeleteProductionDateTime(productionDateTimeToDelete);
                        dbcontext.SaveChanges();
                        return(Ok("Production date time deleted succesfully!"));
                    }
                    catch (Exception e)
                    {
                        // Todo: Catch a specific error so you can tell send a specific response model stating why a production date time was not able to be deleted
                        return(BadRequest("Was not able to delete production date time because....."));
                    }
                }
            }
            catch (Exception e)
            {
                // Todo: User proper error handling responses catch  a more specific error
                return(BadRequest("Major error happened!"));
            }
        }
Exemplo n.º 8
0
        public IHttpActionResult updateProductionDateTime(int productionDateTimeId, [FromBody] ProductionDateTime productionDateTime)
        {
            try
            {
                using (var dbContext = new BroadwayBuilderContext())
                {
                    var productionService = new ProductionService(dbContext);

                    try
                    {
                        if (productionDateTime == null)
                        {
                            return(BadRequest("no date time was provided"));
                        }

                        // Set the production date time id that is to be updated to the id in the uri
                        productionDateTime.ProductionDateTimeId = productionDateTimeId;
                        var updatedProductionDateTime = productionService.UpdateProductionDateTime(productionDateTime);
                        dbContext.SaveChanges();

                        return(Ok(updatedProductionDateTime));
                    }
                    catch (Exception e)
                    {
                        // If none of those if statements were met and we couldnt update a production...
                        return(BadRequest());
                    }
                }
            }
            catch (Exception e)
            {
                // Todo: add proper error response when requet fails due to not being able to create dbcontext...
                return(BadRequest("Something bad happend!"));
            }
        }
Exemplo n.º 9
0
        public IHttpActionResult createProductionDateTime(int productionId, [FromBody] ProductionDateTime productionDateTime)
        {
            try
            {
                using (var dbcontext = new BroadwayBuilderContext())
                {
                    var productionService = new ProductionService(dbcontext);

                    try
                    {
                        if (productionDateTime == null)
                        {
                            return(BadRequest("no production date time object provided"));
                        }

                        productionDateTime.ProductionID = productionId;
                        productionService.CreateProductionDateTime(productionDateTime);
                        dbcontext.SaveChanges();

                        // Todo: Change this to a 201 Created(insert url of resource) once get productiondate time route is created
                        return(Ok(productionDateTime));
                    }
                    catch (Exception e)
                    {
                        return(BadRequest());
                    }
                }
            }
            catch (Exception e)
            {
                return(BadRequest("Something went wrong!"));
            }
        }
        public IHttpActionResult CreateProductionDateTime(int productionId, [FromBody] ProductionDateTime productionDateTime)
        {
            try
            {
                using (var dbcontext = new BroadwayBuilderContext())
                {
                    var productionService = new ProductionService(dbcontext);

                    if (productionDateTime == null)
                    {
                        return(BadRequest("no production date time object provided"));
                    }

                    productionDateTime.ProductionID = productionId;
                    productionService.CreateProductionDateTime(productionId, productionDateTime);
                    dbcontext.SaveChanges();

                    return(Ok("Production Date and time have been added!"));
                }
            }
            catch (DbUpdateException e)
            {
                return(Content((HttpStatusCode)500, e.Message));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
Exemplo n.º 11
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());
                }
            }
        }
Exemplo n.º 12
0
        public void ProductionController_CreateProductionDateTime_Pass()
        {
            // Arrange
            var dbcontext      = new BroadwayBuilderContext();
            var theaterService = new TheaterService(dbcontext);

            var theater = new Theater()
            {
                TheaterName   = "Some Theater 1",
                StreetAddress = "Theater St",
                State         = "CA",
                City          = "LA",
                CompanyName   = "Regal",
                Country       = "US",
                PhoneNumber   = "123456789"
            };

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

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

            var productionService = new ProductionService(dbcontext);

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

            var date = DateTime.Parse("3/23/2019 3:22:29 PM");
            var time = TimeSpan.Parse("10:30:00");

            var productionDateTime = new ProductionDateTime(production.ProductionID, date, time);

            var productionController = new ProductionController();

            // Act
            var actionResult = productionController.CreateProductionDateTime(production.ProductionID, productionDateTime);
            var response     = actionResult as OkNegotiatedContentResult <string>;

            productionService.DeleteProductionDateTime(productionDateTime);
            dbcontext.SaveChanges();
            productionService.DeleteProduction(production.ProductionID);
            dbcontext.SaveChanges();
            theaterService.DeleteTheater(theater);
            dbcontext.SaveChanges();
            // Assert
            Assert.IsNotNull(response);
            Assert.AreEqual("Production Date and time have been added!", response.Content);
        }
Exemplo n.º 13
0
 public ProductionViewModel(IWindowManager windowManager, IEventAggregator eventAggregator, ProductionService productionService)
 {
     _windowManager            = windowManager;
     _eventAggregator          = eventAggregator;
     _productionService        = productionService;
     GridRows                  = new BindableCollection <ProductionBatchEntry>();
     AddProductionBatchCommand = new DelegateCommand(ExecuteAddProductionBatch);
 }
Exemplo n.º 14
0
        public async Task <IActionResult> Create(ProductionViewModel obj)
        {
            ProductionService ps = new ProductionService(_Context);
            bool t = await ps.CreatProductionAsync(obj);

            //return RedirectToAction("Index");
            return(RedirectToAction("Index", new { id = obj.FacId }));
        }
Exemplo n.º 15
0
        public void ProductionService_CreateProduction_Pass()
        {
            // Arrange
            var dbcontext      = new BroadwayBuilderContext();
            var theaterService = new TheaterService(dbcontext);

            var theater = new Theater()
            {
                TheaterName   = "Some Theater",
                StreetAddress = "Theater St",
                State         = "CA",
                City          = "LA",
                CompanyName   = "Regal",
                Country       = "US",
                PhoneNumber   = "123456789"
            };

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

            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
            };

            var expected = true;
            var actual   = false;

            var productionService = new ProductionService(dbcontext);


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

            if (production.ProductionID > 0)
            {
                actual = true;
            }

            // Assert
            var dbcontext_         = new BroadwayBuilderContext();
            var productionService_ = new ProductionService(dbcontext_);

            productionService.DeleteProduction(production.ProductionID);
            dbcontext.SaveChanges();
            theaterService.DeleteTheater(theater);
            dbcontext.SaveChanges();
            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 16
0
        public void ProductionController_DeleteProduction_Pass()
        {
            // Arrange
            var dbcontext      = new BroadwayBuilderContext();
            var theaterService = new TheaterService(dbcontext);

            var theater = new Theater()
            {
                TheaterName   = "Some Theater",
                StreetAddress = "Theater St",
                State         = "CA",
                City          = "LA",
                CompanyName   = "Regal",
                Country       = "US",
                PhoneNumber   = "123456789"
            };

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

            var productionService = new ProductionService(dbcontext);

            var production = new Production
            {
                ProductionName    = "The Pajama Game",
                DirectorFirstName = "Doris",
                DirectorLastName  = "Day",
                City          = "San Diego",
                StateProvince = "California",
                Country       = "U.S",
                TheaterID     = theater.TheaterID,
                Street        = "123 Sesame St",
                Zipcode       = "91911"
            };

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

            var productionController = new ProductionController();

            // Act
            var actionResult = productionController.deleteProduction(production.ProductionID);

            var response = actionResult as OkNegotiatedContentResult <string>;

            var dbcontext_      = new BroadwayBuilderContext();
            var theaterService_ = new TheaterService(dbcontext_);
            var theater_        = theaterService.GetTheaterByID(theater.TheaterID);

            theaterService_.DeleteTheater(theater_);
            dbcontext_.SaveChanges();

            // Assert
            Assert.IsNotNull(response);
            Assert.AreEqual("Production deleted succesfully", response.Content);
        }
Exemplo n.º 17
0
        public void ProductionService_GetProductionById_Pass()
        {
            // Arrange
            var dbcontext      = new BroadwayBuilderContext();
            var theaterService = new TheaterService(dbcontext);

            var theater = new Theater()
            {
                TheaterName   = "The Language",
                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 Pajama Game",
                DirectorFirstName = "Doris",
                DirectorLastName  = "Day",
                City          = "San Diego",
                StateProvince = "California",
                Country       = "U.S",
                TheaterID     = theater.TheaterID,
                Street        = "123 Sesame St",
                Zipcode       = "91911"
            };

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

            var expected = true;
            var actual   = false;

            // Act
            var readProduction = productionService.GetProduction(production.ProductionID);

            if (readProduction != null)
            {
                actual = true;
            }

            // Assert
            productionService.DeleteProduction(production.ProductionID);
            dbcontext.SaveChanges();
            theaterService.DeleteTheater(theater);
            dbcontext.SaveChanges();
            Assert.AreEqual(expected, actual);
        }
        public async Task <ActionResult> Index(SearchModel model)
        {
            ProductionService       service = new ProductionService();
            List <SearchProduction> searchProductionList = await service.search(model.CategoryId, model.Criteria);

            int pageSize   = 16;
            int pageNumber = 1;

            return(PartialView("Index", searchProductionList.ToPagedList(pageNumber, pageSize)));
        }
        public void ProductionService_CreateProductionDateTime_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();

            var date = DateTime.Parse("3/23/2019 3:22:29 PM");
            var time = TimeSpan.Parse("10:30:00");

            /* Info: Had to cast to int because in production entity model int was made into a Nullable<int> or int? for data validation purposes
             * If we make model in frontend then we can remove this cast to int and it will make things cleaner
             */
            var productionDateTime = new ProductionDateTime((int)production.ProductionID, date, time);

            var expected = true;
            var actual   = false;


            // Act
            productionService.CreateProductionDateTime(productionDateTime);
            dbcontext.SaveChanges();

            if (productionDateTime.ProductionDateTimeId > 0)
            {
                actual = true;
            }

            // Assert
            productionService.DeleteProduction(production);
            dbcontext.SaveChanges();
            theaterService.DeleteTheater(theater);
            dbcontext.SaveChanges();
            Assert.AreEqual(expected, actual);
        }
        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);
        }
Exemplo n.º 21
0
        // GET: MySearch
        public ActionResult Index()
        {
            // get 20 first categories for search combobox
            ProductionService service    = new ProductionService();
            List <Category>   categories = Task.Run(() => service.getAllCategories()).Result;

            categories = categories.OrderBy(c => c.CategoryId).Take(20).ToList();

            ViewBag.categories = categories;
            return(PartialView());
        }
Exemplo n.º 22
0
        // GET: Category
        public async Task <ActionResult> Index(int?page)
        {
            // get all categories in system
            ProductionService service    = new ProductionService();
            List <Category>   categories = await service.getAllCategories();

            int pageSize   = 8;
            int pageNumber = (page ?? 1);

            return(View(categories.ToPagedList(pageNumber, pageSize)));
        }
Exemplo n.º 23
0
        public async Task <ActionResult> ReviewProduction(int id)
        {
            ProductionService service       = new ProductionService();
            ReviewDetails     reviewDetails = new ReviewDetails();

            /*{
             *  ProductId,
             *  ProductionName,
             *  MinPrice,
             *  MaxPrice,
             *  Picture,
             *  Color
             * }*/
            // get product info by productId
            reviewDetails.product = await service.getProductionByProductId(id);

            /*
             * {
             *  ReviewId,
             *  Title,
             *  Content,
             *  OverallRating,
             *  UserName,
             *  ReviewDate,
             * }*/
            // get all reviews about a product
            List <ReviewProduction> reviewList = await service.getReviewsByProductId(id);

            reviewDetails.reviewList = reviewList;


            /*
             * rating.oneStarReviewNumber = reviewNumber.Count;
             * rating.twoStarReviewNumber = reviewNumber.Count;
             * rating.threeStarReviewNumber = reviewNumber.Count;
             * rating.fourStarReviewNumber = reviewNumber.Count;
             * rating.fiveStarReviewNumber = reviewNumber.Count;
             *
             * rating.oneStarReviewPercent
             * rating.twoStarReviewPercent
             * rating.threeStarReviewPercent
             * rating.fourStarReviewPercent
             * rating.fiveStarReviewPercent
             *
             * rating.overrallRating */
            // get all rating information of a product
            reviewDetails.rating = await service.getRatingByProductId(id);

            // render View
            return(View(reviewDetails));
        }
Exemplo n.º 24
0
        public IActionResult Index(int Id = -1)
        {
            ProductionService ps = new ProductionService(_Context);
            FactoryService    fs = new FactoryService(_Context);

            ViewBag.factories = fs.GetAllFactoriesSimple();
            List <ProductionViewModel> res = new List <ProductionViewModel>();

            if (Id != -1)
            {
                res = ps.GetallProduction(Id);
            }
            return(View(res));
        }
        public void ProductionService_CreateProduction_Pass()
        {
            var dbcontext      = new BroadwayBuilderContext();
            var theaterService = new TheaterService(dbcontext);

            // Arrange
            var theater = new Theater("someTheater", "Regal", "theater st", "LA", "CA", "US", "323323");

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

            var productionName    = "The Lion King";
            var directorFirstName = "Jane";
            var directorLastName  = "Doe";
            var street            = "Anahiem";
            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);

            var expected = true;
            var actual   = false;

            var productionService = new ProductionService(dbcontext);


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

            if (production.ProductionID > 0)
            {
                actual = true;
            }

            // Assert

            var dbcontext_         = new BroadwayBuilderContext();
            var productionService_ = new ProductionService(dbcontext_);

            productionService.DeleteProduction(production);
            dbcontext.SaveChanges();
            theaterService.DeleteTheater(theater);
            dbcontext.SaveChanges();
            Assert.AreEqual(expected, actual);
        }
        public IHttpActionResult uploadPhoto(int productionId)
        {
            var dbcontext         = new BroadwayBuilderContext();
            var productionService = new ProductionService(dbcontext);

            //try to upload pdf and save to server filesystem
            try
            {
                //get the content, headers, etc the full request of the current http request
                var httpRequest    = HttpContext.Current.Request;
                var fileCollection = httpRequest.Files;

                var fileValidator = new FileValidator();

                int MaxContentLength = 1 * 1024 * 1024 * 5; //Size = 5 MB
                var validExtensions  = new List <string>()
                {
                    ".jpg"
                };
                int maxFileCount = 5;

                var validationResult = fileValidator.ValidateFiles(fileCollection, validExtensions, MaxContentLength, maxFileCount);

                if (!validationResult.ValidationSuccessful)
                {
                    var errorMessage = string.Join("\n", validationResult.Reasons);
                    return(BadRequest(errorMessage));
                }

                // Used for loop since foreach did not handle cycling through multiple files well.
                for (int i = 0; i < httpRequest.Files.Count; i++)
                {
                    // Grab current file of the request
                    HttpPostedFileBase putFile = new HttpPostedFileWrapper(httpRequest.Files[i]);

                    // Send to production service where functinality to save the file is
                    productionService.SavePhoto(productionId, putFile);
                }

                return(Ok("Photo Uploaded"));
            }

            catch (Exception ex) // Todo: log error
            {
                return(BadRequest(ex.Message));
            }
        }
        public IHttpActionResult UploadProductionProgram(int productionId)
        {
            var dbcontext         = new BroadwayBuilderContext();
            var productionService = new ProductionService(dbcontext);

            // Try to upload pdf and save to server filesystem
            try
            {
                // Get the full request of the current http request
                var httpRequest    = HttpContext.Current.Request;
                var fileCollection = httpRequest.Files;

                var fileValidator = new FileValidator();

                int MaxContentLength = 1024 * 1024 * 1;
                int maxFileCount     = 1;
                var extensions       = new List <string>()
                {
                    ".pdf"
                };

                // Validate files for valid extension, and size
                var validationResult = fileValidator.ValidateFiles(fileCollection, extensions, MaxContentLength, maxFileCount);

                if (!validationResult.ValidationSuccessful)
                {
                    var errorMessage = string.Join("\n", validationResult.Reasons);
                    return(BadRequest(errorMessage));
                }

                // Send file to be saved to server
                foreach (string filename in fileCollection)
                {
                    HttpPostedFileBase putFile = new HttpPostedFileWrapper(fileCollection[filename]);


                    productionService.SaveProgram(productionId, putFile);
                }

                return(Ok("Pdf Uploaded"));
            }
            catch (Exception e) { // Todo: log error
                // Todo: add proper error handling in production service
                return(BadRequest(e.Message));
            }
        }
Exemplo n.º 28
0
        public TrayIconContext()
        {
            _productionService = new ProductionService();

            _startCurrent      = new MenuItem("Prøv at  &Starte nuværende indhold (Ctrl+Alt+Shift+S)", StartCurrent);
            _whatsOnModeToggle = new MenuItem("WhatsOn Mode (Ctrl+Alt+Shift+W)", ToggleWhatsOnMode);

            if (!Clipboard.ContainsText() || !SafeToStart(Clipboard.GetText()))
            {
                _startCurrent.Enabled = false;
            }
            _baseItems = new[]
            {
                new MenuItem("-"),
                _startCurrent,
                _whatsOnModeToggle,
                new MenuItem("&Om", About),
                new MenuItem("&Afslut", Exit),
            };

            var icon = new Icon(_assembly.GetManifestResourceStream("DR.NummerStripper.Icon.ico") ??
                                throw new InvalidOperationException());

            _trayIcon = new NotifyIcon()
            {
                Icon        = icon,
                ContextMenu = new ContextMenu(_baseItems),
                Visible     = true,
                Text        = "DR Udklipsholderhjælper",
            };

            _trayIcon.Click             += Click;
            _trayIcon.BalloonTipClicked += StartCurrent;
            _clipboard = new SharpClipboard {
                ObservableFormats = { Texts = true, Images = false, Files = false, Others = false }
            };
            _clipboard.ClipboardChanged += ClipboardChanged;
            _clipboard.StartMonitoring();
            _startHook = new KeyboardHook();
            _startHook.RegisterHotKey(ModifierKeys.Control | ModifierKeys.Alt | ModifierKeys.Shift, Keys.S);
            _startHook.KeyPressed += StartCurrent;
            _whatsOnHook           = new KeyboardHook();
            _whatsOnHook.RegisterHotKey(ModifierKeys.Control | ModifierKeys.Alt | ModifierKeys.Shift, Keys.W);
            _whatsOnHook.KeyPressed += ToggleWhatsOnMode;
        }
Exemplo n.º 29
0
        public async Task <ActionResult> Index(int categoryId, int?page)
        {
            DBModelContainer  db      = new DBModelContainer();
            ProductionService service = new ProductionService();

            // get all products of a given category
            List <Production> prs = await service.getProductsByCategoryId(categoryId);

            if (prs != null && prs.Count > 0)
            {
                int pageSize   = 16;
                int pageNumber = (page ?? 1);

                return(View(prs.ToPagedList(pageNumber, pageSize)));
            }

            return(RedirectToAction("Index", "Category"));
        }
Exemplo n.º 30
0
        public async Task <ActionResult> ProductDetail(int id)
        {
            DBModelContainer db = new DBModelContainer();
            ProductionDetail pr = new ProductionDetail();

            pr.ProductId = id;

            // get product title equal to CategoryName + " > " + names.ProductName;
            ProductionService service = new ProductionService();

            pr.Title = (await service.getProductTitleByProductId(id)).Title;

            /*{
             *  Color,
             *  Description,
             *  Price,
             *  Size,
             *  Amount,
             *  Picture,
             *  ProductDetailsId,
             *  ProductId,
             *  ProductionName
             * }*/
            // get all productDetails by a given product
            pr.listdata = await service.getProductDetailsByProductId(id);

            /*{
             *  ProductId,
             *
             *  Title,
             *  Content,
             *  OverallRating,
             *
             *  ReviewId,
             *  UserId,
             *  UserName,
             *  ReviewDate
             * }*/
            // get all reviews about a given product
            pr.reviewListData = await service.getReviewsByProductId(id);

            return(View(pr));
        }
Exemplo n.º 31
0
 public void OnMessageAdded(ProductionService.ProductionAidDTO order, DateTime timestamp)
 {
 }