Exemplo n.º 1
0
 public ActionResult CreateProjection([FromBody] ProjectionViewModel model)
 {
     try
     {
         Movie movie = dbHandler.Movies.FirstOrDefault(x => x.Id.ToString() == model.Movie.Id);
         if (movie is null)
         {
             return(BadRequest());
         }
         Theater theater = dbHandler.Theaters.FirstOrDefault(x => x.Id.ToString() == model.Theater.Id);
         if (theater is null)
         {
             return(BadRequest());
         }
         Projection projection = new Projection
         {
             ProjectionDate = model.ProjectionDate,
             Movie          = movie,
             Theater        = theater
         };
         dbHandler.Projections.Add(projection);
         dbHandler.SaveChanges();
         return(Ok());
     } catch (Exception)
     {
         return(BadRequest());
     }
 }
Exemplo n.º 2
0
        public ActionResult UpdateProjection([FromBody] ProjectionViewModel model)
        {
            Projection projection = dbHandler.Projections.Include(x => x.Movie).Include(x => x.Theater).FirstOrDefault(x => x.Id.ToString() == model.Id);

            if (projection is null)
            {
                return(BadRequest());
            }

            if (projection.Theater.Id.ToString() != model.Theater.Id)
            {
                Theater theater = dbHandler.Theaters.FirstOrDefault(x => x.Id.ToString() == model.Theater.Id);
                projection.Theater = theater ?? projection.Theater;
            }
            if (projection.Movie.Id.ToString() != model.Movie.Id)
            {
                Movie movie = dbHandler.Movies.FirstOrDefault(x => x.Id.ToString() == model.Movie.Id);
                projection.Movie = movie ?? projection.Movie;
            }
            projection.ProjectionDate = (projection.ProjectionDate != model.ProjectionDate && model.ProjectionDate != DateTime.Parse("10/10/1000").Date) ? model.ProjectionDate : projection.ProjectionDate;

            try
            {
                dbHandler.Projections.Update(projection);
                dbHandler.SaveChanges();
                return(Ok());
            } catch (Exception)
            {
                return(BadRequest());
            }
        }
Exemplo n.º 3
0
        public JsonResult GetProjections(int cinemaID, int movieID)
        {
            db.Configuration.ProxyCreationEnabled = false;

            Cinema                     currentCinema           = db.Cinema.Find(cinemaID);
            List <Room>                currentCinemaRooms      = db.Room.Where(r => r.cinema_id == cinemaID).ToList();
            Movie                      currentMovie            = db.Movie.Find(movieID);
            List <Projection>          movieProjections        = new List <Projection>();
            List <ProjectionViewModel> movieProjectionsForView = new List <ProjectionViewModel>();

            foreach (var projection in db.Projection)
            {
                Room currentRoom          = db.Room.Find(projection.room_id);
                int  currentRoomSeatCount = 0;
                foreach (var seat in db.Seat)
                {
                    if (seat.room_id == currentRoom.id)
                    {
                        currentRoomSeatCount++;
                    }
                }
                // if the projection has the same Movie
                if (projection.movie_id == movieID)
                {
                    bool sameCinema = false;
                    foreach (var room in currentCinemaRooms)
                    {
                        //if the projection is in the same CINEMA
                        if (room.id == projection.room_id)
                        {
                            sameCinema = true;
                            break;
                        }
                    }
                    if (sameCinema)
                    {
                        movieProjections.Add(projection);
                        int takenSeats = 0;
                        foreach (var ticket in db.Ticket)
                        {
                            if (ticket.projection_id == projection.id)
                            {
                                takenSeats++;
                            }
                        }

                        ProjectionViewModel pvm = new ProjectionViewModel
                        {
                            Id        = projection.id,
                            StartDate = projection.start_date,
                            RoomID    = projection.room_id,
                            FreeSeats = currentRoomSeatCount - takenSeats
                        };
                        movieProjectionsForView.Add(pvm);
                    }
                }
            }
            return(Json(movieProjectionsForView, JsonRequestBehavior.AllowGet));
        }
        public ActionResult AddProjection()
        {
            ProjectionViewModel model = new ProjectionViewModel();

            model.Movies = MovieService.GetMovies();
            model.Halls  = HallService.GetHalls();
            return(PartialView(model));
        }
Exemplo n.º 5
0
        } // End calculateKG

        /// <summary>
        /// Calculates the amount of sheets
        /// </summary>
        /// <param name="Projection"></param>
        /// <param name="Month"></param>
        /// <returns></returns>
        public double CalculateSheet(ProjectionViewModel Projection, string Month)
        {
            double cantidadProyectada = Month == null ? 0 : Double.Parse(Month);
            double montaje            = Projection.Montaje == null ? 0 : (double)Projection.Montaje;
            double pliegos            = Projection.Pliegos == null ? 0 : (double)Projection.Pliegos;
            double paginas            = Projection.Paginas == null ? 0 : (double)Projection.Paginas;
            double result             = (cantidadProyectada / montaje) * (paginas / pliegos);

            return(Double.IsInfinity(result) || Double.IsNaN(result) ? 0 : Math.Round(result, 4));
        } // End calculateSheet
Exemplo n.º 6
0
        public ActionResult Destroy([DataSourceRequest] DataSourceRequest request, ProjectionViewModel model)
        {
            if (model != null && ModelState.IsValid)
            {
                Mapper.CreateMap <ProjectionViewModel, Projection>();
                var dbModel = Mapper.Map <Projection>(model);
                this.Data.Projections.Delete(dbModel);
                this.Data.SaveChanges();
            }

            return(Json(new[] { model }.ToDataSourceResult(request, ModelState)));
        }
Exemplo n.º 7
0
        public ActionResult CreateProjection(ProjectionViewModel projectionViewModel)
        {
            Projection projection = new Projection();

            projection.TrainerID   = projectionViewModel.TrainerID;
            projection.VendorID    = projectionViewModel.VendorID;
            projection.ProjectFrom = DateTime.ParseExact(projectionViewModel.ProjectFrom, "dd/MM/yyyy", CultureInfo.InvariantCulture);
            projection.ProjectTo   = DateTime.ParseExact(projectionViewModel.ProjectTo, "dd/MM/yyyy", CultureInfo.InvariantCulture);
            //Sdate = Convert.ToDateTime(Sdate).ToString("dd/MM/yyyy");
            db.Projections.Add(projection);
            db.SaveChanges();
            return(View());
        }
Exemplo n.º 8
0
        public ActionResult Update([DataSourceRequest] DataSourceRequest request, ProjectionViewModel model)
        {
            if (model != null && ModelState.IsValid)
            {
                var projection = this.Data.Projections.All().FirstOrDefault(p => p.Id == model.Id);
                projection.Hall.CinemaId = model.CinemaId;
                Mapper.CreateMap <ProjectionViewModel, Projection>();
                Mapper.Map(model, projection);
                this.Data.SaveChanges();
                model.MovieName  = projection.Movie.Title;
                model.HallNumber = projection.Hall.Number;
                model.CinemaName = projection.Hall.Cinema.Name;
            }

            return(Json(new[] { model }.ToDataSourceResult(request, ModelState)));
        }
Exemplo n.º 9
0
        // GET: Client
        public ActionResult Index()
        {
            var trainerList = new SelectList(db.Trainers, "TrainerID", "TrainerName");

            /* var trainerList = db.Trainers.Select(x=>x.TrainerID).ToList();
             * SelectList selectListItems = new SelectList;
             * var trainerList = (from t in db.Trainers
             *                  select new ProjectionViewModel()
             *                  {
             *                     TrainerID = t.TrainerID
             *                  }).ToList();*/

            var proj = new ProjectionViewModel();

            proj.TrainerList = trainerList;
            return(View(proj));
        }
Exemplo n.º 10
0
        public ActionResult Create([DataSourceRequest] DataSourceRequest request, ProjectionViewModel model)
        {
            if (model != null && ModelState.IsValid)
            {
                Mapper.CreateMap <ProjectionViewModel, Projection>();
                var dbModel = Mapper.Map <Projection>(model);
                var hall    = this.Data.Halls.All().FirstOrDefault(h => h.Id == model.HallId);
                hall.CinemaId = model.CinemaId;
                this.Data.Projections.Add(dbModel);
                this.Data.SaveChanges();
                model.Id         = dbModel.Id;
                model.MovieName  = this.Data.Movies.All().FirstOrDefault(m => m.Id == dbModel.MovieId).Title;
                model.HallNumber = this.Data.Halls.All().FirstOrDefault(h => h.Id == dbModel.HallId).Number;
                model.CinemaName = hall.Cinema.Name;
            }

            return(Json(new[] { model }.ToDataSourceResult(request, ModelState)));
        }
Exemplo n.º 11
0
        public void CalculateSheetsBox()
        {
            //Arrange
            ProjectionContext projectionContext = new ProjectionContext();
            SapDataContext    sapDataContext    = new SapDataContext();
            Check             check             = new Check(projectionContext, sapDataContext);
            //Act
            ProjectionViewModel projection = new ProjectionViewModel();

            projection.Ancho_Pliego = 445;
            projection.Largo_Pliego = 838;
            projection.Montaje      = 4;
            projection.Pliegos      = 2;
            projection.Paginas      = 2;
            projection.Gramaje      = 44;
            double sheetTotal = check.CalculateSheet(projection, "5000"); // el segundo valor es la proyección

            //Assert
            Assert.AreEqual(sheetTotal, 1250);
        }
Exemplo n.º 12
0
        public void CalculateKGBox()
        {
            //Arrange
            ProjectionContext projectionContext = new ProjectionContext();
            SapDataContext    sapDataContext    = new SapDataContext();
            Check             check             = new Check(projectionContext, sapDataContext);
            //Act
            ProjectionViewModel projection = new ProjectionViewModel();

            projection.Ancho_Pliego = 981;
            projection.Largo_Pliego = 576;
            projection.Montaje      = 2;
            projection.Pliegos      = 1;
            projection.Paginas      = 2;
            projection.Gramaje      = 352;
            double kgTotal = check.CalculateKG(projection, "168750"); // el segundo valor es la proyección

            //Assert
            Assert.AreEqual(kgTotal, 16782.1632);
        }
Exemplo n.º 13
0
        public void CalculateKGBooks()
        {
            //Arrange
            ProjectionContext projectionContext = new ProjectionContext();
            SapDataContext    sapDataContext    = new SapDataContext();
            Check             check             = new Check(projectionContext, sapDataContext);
            //Act
            ProjectionViewModel projection = new ProjectionViewModel();

            projection.Ancho_Pliego = 445;
            projection.Largo_Pliego = 838;
            projection.Montaje      = 1;
            projection.Pliegos      = 16;
            projection.Paginas      = 48;
            projection.Gramaje      = 44;
            double kgTotal = check.CalculateKG(projection, "5000"); // el segundo valor es la proyección

            //Assert
            Assert.AreEqual(kgTotal, 246.1206);
        }
Exemplo n.º 14
0
        } // End InsertNewBudgets

        /// <summary>
        /// Calculates the KG of each month
        /// </summary>
        /// <param name="Projection"></param>
        /// <param name="Month"></param>
        /// <returns></returns>
        public double CalculateKG(ProjectionViewModel Projection, string Month)
        {
            double anchoPliego       = Projection.Ancho_Pliego == null ? 0 : (double)Projection.Ancho_Pliego;
            double largoPliego       = Projection.Largo_Pliego == null ? 0 : (double)Projection.Largo_Pliego;
            double cantidadRequerida = Projection.Paginas > 2 ? CalculateSheet(Projection, Month) : double.Parse(Month);
            double montaje           = Projection.Montaje == null ? 0 : (double)Projection.Montaje;
            double pliegos           = Projection.Pliegos == null ? 0 : (double)Projection.Pliegos;
            double gramaje           = Projection.Gramaje == null ? 0 : (double)Projection.Gramaje;

            if (Projection.Paginas > 2)
            {
                double result = (((anchoPliego * largoPliego) / 1000000) *
                                 (cantidadRequerida)) * (gramaje / 1000);
                return(Double.IsInfinity(result) || Double.IsNaN(result) ? 0 : Math.Round(result, 4));
            }
            else
            {
                double result = (((anchoPliego * largoPliego) / 1000000) *
                                 (cantidadRequerida / montaje)) * (gramaje / 1000);
                return(Double.IsInfinity(result) || Double.IsNaN(result) ? 0 : Math.Round(result, 4));
            }
        } // End calculateKG
Exemplo n.º 15
0
        } // End GetMonthName

        /// <summary>
        /// Line by line, inserts the new budget with all the properties
        /// </summary>
        /// <param name="row"></param>
        /// <param name="lineNumber"></param>
        /// <param name="lastDocument"></param>
        private void InsertSingleBudget(ProjectionViewModel row, uint lineNumber, ushort lastDocument)
        {
            DetailPipeline pipelineModel = new DetailPipeline();
            var            codigoCliente = _projectionContext.Vista_SAP.Where(s => s.U_OrdenProduccionMet == row.ItemCodeSustrato).Select(p => p.CardCode).SingleOrDefault();

            pipelineModel.Ejecutivo        = row.Ejecutivo;
            pipelineModel.Cliente          = row.Cliente;
            pipelineModel.Producto         = row.Producto;
            pipelineModel.Presupuesto      = row.Presupuesto;
            pipelineModel.ItemCodeSustrato = row.ItemCodeSustrato;
            pipelineModel.Sustrato         = row.Sustrato;
            pipelineModel.Gramaje          = row.Gramaje == null ? 0 : (int)row.Gramaje;
            pipelineModel.AnchoBobina      = row.Ancho_Bobina == null ? 0 : (int?)row.Ancho_Bobina;
            pipelineModel.AnchoPliego      = row.Ancho_Pliego == null ? 0 : (int?)row.Ancho_Pliego;
            pipelineModel.LargoPliego      = row.Largo_Pliego == null ? 0 : (int?)row.Largo_Pliego;
            pipelineModel.Paginas          = row.Paginas == null ? 0 : row.Paginas;
            pipelineModel.Montaje          = row.Montaje == null ? 0 : (int?)row.Montaje;
            pipelineModel.Pliegos          = row.Pliegos == null ? 0 : row.Pliegos;
            pipelineModel.IdDoc            = lastDocument + 1;
            pipelineModel.IdLinea          = (int?)lineNumber;
            pipelineModel.FechaHora        = DateTime.Now;
            pipelineModel.CardName         = codigoCliente;
            _projectionContext.Entry(pipelineModel).State = EntityState.Added;
        } // End InsertSingelBudget
Exemplo n.º 16
0
        } // End InsertSingelBudget

        /// <summary>
        /// Inserts a new line of projections with a new document number meanwhile holding the value from past documents/budgets
        /// </summary>
        /// <param name="item">Contains the data of each budgets</param>
        /// <param name="lineNumber">The line number of the main query</param>
        /// <param name="lastDocument">Last document number</param>
        public void InsertProjections(ProjectionViewModel row, uint lineNumber, ushort lastDocument, SessionViewModel session)
        {
            ConversionProcess listaReserva = (from Reserva in _projectionContext.A_Vista_OConversion_Reserva
                                              where Reserva.Presupuesto == row.Presupuesto && Reserva.Material == row.ItemCodeSustrato
                                              join kgPapel in _projectionContext.VU_ACR_DON_012_OrcPapel on new
            {
                CodigoPapel = Reserva.Material,
                OP = Reserva.NumOrdem
            }
                                              equals new
            {
                CodigoPapel = kgPapel.CodSubConta,
                OP = kgPapel.NumOrdem
            }
                                              select new ConversionProcess
            {
                TotalKilogramosPorCodigo = kgPapel.totKgCot
            }).FirstOrDefault();

            string NombreProceso = row.Lote.Substring(0, row.Lote.IndexOf('-') == -1 ?
                                                      row.Lote.Length : row.Lote.IndexOf('-'));

            List <ProjectionKg> cantidadEnUnidades =
                (from Lote in _projectionContext.OrdLotesProducao
                 where Lote.DataTermino >= session.StartDate && Lote.NumOrdem == row.NumOrdem
                 select new ProjectionKg
            {
                NumOrdem = Lote.NumOrdem,
                IdLote = Lote.IdLote,
                Lote = Lote.IdComponente,
                CantidadUnidades = Lote.Quantidade,
                FechaDeTermino = Lote.DataTermino
            }).ToList();

            DetailPipelineTotales pipelineTotales = new DetailPipelineTotales();

            pipelineTotales.IdDoc             = lastDocument + 1;
            pipelineTotales.IdLine            = (int?)lineNumber;
            pipelineTotales.Mes               = cantidadEnUnidades.Select(p => p.FechaDeTermino).Min().Month;
            pipelineTotales.Año               = cantidadEnUnidades.Select(p => p.FechaDeTermino).Min().Year;
            pipelineTotales.Cantidad          = row.Quantidade;
            pipelineTotales.CantidadKilos     = (decimal)listaReserva.TotalKilogramosPorCodigo;
            pipelineTotales.Presupuestos      = row.Presupuesto;
            pipelineTotales.ItemCodeSustrato  = row.ItemCodeSustrato;
            pipelineTotales.NumeroPresupuesto = row.NumOrdem;
            _projectionContext.Entry(pipelineTotales).State = EntityState.Added;

            foreach (ProjectionKg kgItem in cantidadEnUnidades.Where(p => p.Lote.Substring(0, p.Lote.IndexOf
                                                                                               ('-') == -1 ? p.Lote.Length : p.Lote.IndexOf('-')).Equals(NombreProceso)))
            {
                DetailPipelineEntregas month = new DetailPipelineEntregas();
                month.Cantidad = kgItem.CantidadUnidades;
                double unidadesEntreTotalPorLote = (double)kgItem.CantidadUnidades / (double)row.Quantidade;
                month.CantidadKilos = (decimal?)(unidadesEntreTotalPorLote * listaReserva.TotalKilogramosPorCodigo);
                month.IdDoc         = lastDocument + 1;
                month.IdLine        = (int?)lineNumber;
                month.Mes           = kgItem.FechaDeTermino.Month;
                month.Año           = kgItem.FechaDeTermino.Year;
                month.Presupuestos  = row.Presupuesto;
                _projectionContext.Entry(month).State = EntityState.Added;
                //detail.Add(month);
            }
        } // End GetProjections
Exemplo n.º 17
0
 public ActionResult Index(ProjectionViewModel projectionViewModel)
 {
     return(View());
 }