private void ProcessBasicShiftTypes(DateTime currentDate, ProductionLineSchedule schedule,
                                            ProductionShiftUse entity)
        {
            switch (currentDate.DayOfWeek)
            {
            case DayOfWeek.Sunday:
                schedule.MinutesScheduled = entity.Day1Minutes;
                break;

            case DayOfWeek.Monday:
                schedule.MinutesScheduled = entity.Day2Minutes;
                break;

            case DayOfWeek.Tuesday:
                schedule.MinutesScheduled = entity.Day3Minutes;
                break;

            case DayOfWeek.Wednesday:
                schedule.MinutesScheduled = entity.Day4Minutes;
                break;

            case DayOfWeek.Thursday:
                schedule.MinutesScheduled = entity.Day5Minutes;
                break;

            case DayOfWeek.Friday:
                schedule.MinutesScheduled = entity.Day6Minutes;
                break;

            case DayOfWeek.Saturday:
                schedule.MinutesScheduled = entity.Day7Minutes;
                break;
            }
        }
 private void AddScheduleToRepository(ProductionLineSchedule schedule)
 {
     if (schedule.ID == 0)
     {
         _repository.Repository <ProductionLineSchedule>().Insert(schedule);
     }
     else
     {
         _repository.Repository <ProductionLineSchedule>().Update(schedule);
     }
 }
        private void ProcessShiftType3(DateTime currentDate, ProdDateChange prodDateChange,
                                       ProductionLineSchedule schedule, ProductionShiftUse entity)
        {
            switch (Math.Abs((currentDate - prodDateChange.RotationStart).Days) % 14)
            {
            case 0:
            case 1:
            case 4:
            case 5:
            case 6:
            case 9:
            case 10:
                switch (currentDate.DayOfWeek)
                {
                case DayOfWeek.Sunday:
                    schedule.MinutesScheduled = entity.Day1Minutes;
                    break;

                case DayOfWeek.Monday:
                    schedule.MinutesScheduled = entity.Day2Minutes;
                    break;

                case DayOfWeek.Tuesday:
                    schedule.MinutesScheduled = entity.Day3Minutes;
                    break;

                case DayOfWeek.Wednesday:
                    schedule.MinutesScheduled = entity.Day4Minutes;
                    break;

                case DayOfWeek.Thursday:
                    schedule.MinutesScheduled = entity.Day5Minutes;
                    break;

                case DayOfWeek.Friday:
                    schedule.MinutesScheduled = entity.Day6Minutes;
                    break;

                case DayOfWeek.Saturday:
                    schedule.MinutesScheduled = entity.Day7Minutes;
                    break;
                }
                break;

            default:
                schedule.MinutesScheduled = 0;
                break;
            }
        }
        public int Add(ProductionLineScheduleDto dto)
        {
            int result = -1;
            var entity = new ProductionLineSchedule();

            try
            {
                Mapper.Map(dto, entity);
                _repository.Repository <ProductionLineSchedule>().Insert(entity);
                _repository.Save();

                if (entity != null)
                {
                    result = entity.ID;
                }
            }
            catch (DbEntityValidationException valEx)
            {
                var sb = new StringBuilder();

                foreach (var failure in valEx.EntityValidationErrors)
                {
                    sb.AppendFormat("{0} failed validation\n", failure.Entry.Entity.GetType());
                    foreach (var error in failure.ValidationErrors)
                    {
                        sb.AppendFormat("- {0} : {1}", error.PropertyName, error.ErrorMessage);
                        sb.AppendLine();
                    }
                }

                throw new DbEntityValidationException(
                          "Entity Validation Failed - errors follow:\n" +
                          sb.ToString(), valEx
                          ); // Add the original exception as the innerException
            }
            catch (Exception exc)
            {
                throw new Exception("Error occurred while adding item.", exc);
            }

            return(result);
        }
        private void ProcessShiftRotation(ProductionShiftUse entity, DateTime currentDate, ProdDateChange prodDateChange,
                                          ProductionLineSchedule schedule)
        {
            switch (entity.ProductionShift.ProductionShiftType.Code)
            {
            case "3":
                ProcessShiftType3(currentDate, prodDateChange, schedule, entity);
                break;

            case "4":
                ProcessShiftType4(currentDate, prodDateChange, schedule, entity);
                break;

            case "5":
                ProcessShiftType5(currentDate, prodDateChange, schedule, entity);
                break;

            default:
                ProcessBasicShiftTypes(currentDate, schedule, entity);
                break;
            }
        }
        private ProductionLineSchedule GetSchedule(ProductionShiftUseDto dto, ProductionShiftUse entity, DateTime currentDate)
        {
            var schedule =
                entity.ProductionShift.ProductionLineSchedules.FirstOrDefault(
                    s => s.ProductionDate == currentDate);

            if (schedule == null)
            {
                schedule = new ProductionLineSchedule()
                {
                    PlantID        = dto.PlantID,
                    LineID         = dto.LineID,
                    ShiftID        = dto.ShiftID,
                    ProductionDate = currentDate,
                    DateEntered    = DateTime.Now,
                    LastModified   = DateTime.Now
                }
            }
            ;

            schedule.LastModified = DateTime.Now;
            schedule.ModifiedBy   = CurrentUserName;
            return(schedule);
        }