private IEnumerable <ProductionShiftUseModel> AddMissingShifts(List <ProductionShiftUseDto> shifts, int lineId)
        {
            List <ProductionShiftUseModel> additionalShifts = new List <ProductionShiftUseModel>();

            using (ProductionShiftService service = new ProductionShiftService())
            {
                var dtos = service.GetAllByPlantId(CurrentPlantId);
                foreach (var dto in dtos)
                {
                    if (shifts.FirstOrDefault(s => s.ShiftID == dto.ID) != null)
                    {
                        continue;
                    }
                    ProductionShiftUseModel additionalShift = new ProductionShiftUseModel()
                    {
                        PlantId     = CurrentPlantId,
                        LineID      = lineId,
                        Day1Minutes = 0,
                        Day2Minutes = 0,
                        Day3Minutes = 0,
                        Day4Minutes = 0,
                        Day5Minutes = 0,
                        Day6Minutes = 0,
                        Day7Minutes = 0,
                        ShiftCode   = dto.Code,
                        ShiftID     = dto.ID
                    };
                    additionalShifts.Add(additionalShift);
                }
            }
            return(additionalShifts);
        }
        public JsonResult InsertShift(string row)
        {
            TPO.Web.Core.ResponseMessage responseMessage;

            ProductionShiftModel productionShift = JsonConvert.DeserializeObject <ProductionShiftModel>(row);

            try
            {
                if (productionShift != null)
                {
                    productionShift.LastModified = DateTime.Now;
                    productionShift.DateEntered  = DateTime.Now;
                    productionShift.EnteredBy    = CurrentUser;
                    productionShift.ModifiedBy   = CurrentUser;
                    productionShift.PlantId      = CurrentPlantId;
                    productionShift.Code         = LookupShiftTypeCode(productionShift.TypeID);
                    ProductionShiftDto dto = new ProductionShiftDto();
                    using (ProductionShiftService service = new ProductionShiftService())
                    {
                        Mapper.Map(productionShift, dto);
                        service.Add(dto);
                    }
                }

                responseMessage = SetResponseMesssage(ActionTypeMessage.SuccessfulSave);
            }
            catch (Exception exc)
            {
                responseMessage = SetResponseMesssage(ActionTypeMessage.FailedSave, exc.Message);
            }

            productionShift.ResponseMessage = responseMessage;

            return(Json(productionShift, JsonRequestBehavior.AllowGet));
        }
        public JsonResult DeleteShift(string row)
        {
            TPO.Web.Core.ResponseMessage responseMessage;

            ProductionShiftModel productionShift = JsonConvert.DeserializeObject <ProductionShiftModel>(row);

            try
            {
                if (productionShift != null && productionShift.Id > 0)
                {
                    using (ProductionShiftService service = new ProductionShiftService())
                    {
                        service.Delete(productionShift.Id);
                    }
                }

                responseMessage = SetResponseMesssage(ActionTypeMessage.SuccessfulSave);
            }
            catch (Exception exc)
            {
                responseMessage = SetResponseMesssage(ActionTypeMessage.FailedSave, exc.Message);
            }

            productionShift.ResponseMessage = responseMessage;

            return(Json(productionShift, JsonRequestBehavior.AllowGet));
        }
        public JsonResult FetchGridInfo(int productionLineId, DateTime week)
        {
            List <ProductionLineScheduleWeekly> items = new List <ProductionLineScheduleWeekly>();
            List <ProductionLineScheduleDto>    entities;

            List <ProductionShiftDto> shifts;

            using (ProductionShiftService service = new ProductionShiftService())
                shifts = service.GetAllByPlantId(CurrentPlantId);

            foreach (ProductionShiftDto shift in shifts)
            {
                using (ProductionLineScheduleService service = new ProductionLineScheduleService())
                    entities = service.GetWeekly(CurrentPlantId, shift.ID, productionLineId, GetFirstDayOfWeek(week));

                if (entities.Count == 0)
                {
                    items.Add(CreateWeeklyInfo(shift));
                }
                else
                {
                    items.Add(PopulateWeeklyInfo(shift, entities));
                }
            }



            return(Json(items, JsonRequestBehavior.AllowGet));
        }
        public JsonResult GetProductionShift()
        {
            List <ProductionShiftModel> model = new List <ProductionShiftModel>();

            using (ProductionShiftService svc = new ProductionShiftService())
            {
                var dtos = svc.GetAll();
                model.AddRange(Mapper.Map <List <ProductionShiftDto>, List <ProductionShiftModel> >(dtos));
            }
            return(Json(model, JsonRequestBehavior.AllowGet));
        }
        public JsonResult GetAllProductionShifts()
        {
            List <ProductionShiftModel> productionShifts = new List <ProductionShiftModel>();

            using (ProductionShiftService svc = new ProductionShiftService())
            {
                var dtos = svc.GetAllByPlantId(CurrentPlantId);
                productionShifts.AddRange(Mapper.Map <List <ProductionShiftDto>, List <ProductionShiftModel> >(dtos));
            }
            return(Json(productionShifts, JsonRequestBehavior.AllowGet));
        }