public ActionResult Edit(TPOProduct model)
        {
            model.LastModified = DateTime.Now;
            model.ModifiedBy   = CurrentUser;
            model.DateEntered  = DateTime.Now;
            model.EnteredBy    = CurrentUser;
            model.PlantId      = CurrentPlantId;

            if (ModelState.IsValid)
            {
                TPOProductDto dto = Mapper.Map <TPOProduct, TPOProductDto>(model);

                //TODO: move to service
                using (var service = new TPOProductService())
                {
                    if (model.Id > 0)
                    {
                        service.Update(dto);
                    }
                    else
                    {
                        service.Add(dto);
                    }
                }

                SetResponseMesssage(ActionTypeMessage.SuccessfulSave);
            }
            else
            {
                ModelState.AddModelError(string.Empty, "Please enter required fields.");
                SetResponseMesssage(ActionTypeMessage.FailedSave);
                return(View(model));
            }
            return(RedirectToAction("Edit"));
        }
        public JsonResult GetProdLinePerformanceProd(int prodLineId)
        {
            ProductionLinesModel productionLine = GetProductionLine(prodLineId);
            List <ProdLinesPerformanceTargetProductModel> prodLineProducts = new List <ProdLinesPerformanceTargetProductModel>();

            using (ProdLinesPerformProdService service = new ProdLinesPerformProdService())
            {
                var dtos = service.GetByProdLineId(prodLineId);
                prodLineProducts.AddRange(Mapper.Map <List <ProdLinesPerformProdDto>, List <ProdLinesPerformanceTargetProductModel> >(dtos));
            }
            using (TPOProductService productService = new TPOProductService())
            {
                var dtos = productService.GetAllByProdLineId(prodLineId);
                foreach (var dto in dtos)
                {
                    if (prodLineProducts.FirstOrDefault(p => p.ProductID == dto.ID) != null)
                    {
                        continue;
                    }
                    prodLineProducts.Add(
                        new ProdLinesPerformanceTargetProductModel()
                    {
                        LocID       = productionLine.PlantId,
                        ProdLineID  = prodLineId,
                        ProductID   = dto.ID,
                        ProductName = dto.ProductCode,
                        Throughput  = 0,
                    }
                        );
                }
            }
            return(Json(prodLineProducts, JsonRequestBehavior.AllowGet));
        }
        public JsonResult AllProductsResult()
        {
            List <TPOProductDto> dtos = new List <TPOProductDto>();

            using (TPOProductService svc = new TPOProductService())
            {
                dtos.AddRange(svc.GetByPlant(CurrentPlantId));
            }
            return(Json(dtos, JsonRequestBehavior.AllowGet));
        }
        public JsonResult GetByPlantResult()
        {
            List <TPOProduct> products = new List <TPOProduct>();

            using (TPOProductService svc = new TPOProductService())
            {
                var dtos = svc.GetByPlant(CurrentPlantId);
                products.AddRange(Mapper.Map <List <TPOProductDto>, List <TPOProduct> >(dtos));
            }
            return(Json(products, JsonRequestBehavior.AllowGet));
        }
        public JsonResult GetReworkProducts(int productInID = 0)
        {
            List <TPOProduct> data = new List <TPOProduct>();

            using (TPOProductService svc = new TPOProductService())
            {
                var dtos = svc.GetReworkProducts(productInID);
                data.AddRange(Mapper.Map <List <TPOProductDto>, List <TPOProduct> >(dtos));
            }
            return(Json(data, JsonRequestBehavior.AllowGet));
        }
        public JsonResult GetReclaimMaterialResult()
        {
            List <TPOProduct> data = new List <TPOProduct>();

            using (TPOProductService svc = new TPOProductService())
            {
                var dtos = svc.GetAll().FindAll(p => p.IsREPEL == true);
                data.AddRange(Mapper.Map <List <TPOProductDto>, List <TPOProduct> >(dtos));
            }
            return(Json(data, JsonRequestBehavior.AllowGet));
        }
        //
        // GET: /TPOProduct/Edit/5
        public ActionResult Edit(int id = 0)
        {
            if (id == 0)
            {
                return(View(new TPOProduct()));
            }
            using (var service = new TPOProductService())
            {
                TPOProduct model =
                    Mapper.Map <TPOProductDto, TPOProduct>(service.Get(id));

                return(View(model));
            }
        }