コード例 #1
0
        //Check Availabilities when changing default jobs to override jobs & vice versa
        public TimeSlotAvailabilityRequest CheckExistingDefaultsForOverride(DateTime?QueryDate, int?QueryScheduleId)
        {
            TimeSlotAvailabilityRequest c = new TimeSlotAvailabilityRequest();

            //will need to switch to v2 soon
            DataProvider.ExecuteCmd(GetConnection, "dbo.JobTimeSlots_SelectCapacityByDate"
                                    , inputParamMapper : delegate(SqlParameterCollection paramCollection)
            {
                paramCollection.AddWithValue("@QueryDate", QueryDate);
                paramCollection.AddWithValue("@QueryScheduleId", QueryScheduleId);
            }, map : delegate(IDataReader reader, short set)
            {
                if (set == 0)
                {
                    c.CurrentAvailable = reader.GetSafeInt32(0);
                }
                else if (set == 1)
                {
                    c.CurrentUsed = reader.GetSafeInt32(0);
                }
            });



            return(c);
        }
コード例 #2
0
        //Adding Overrides And Default Time Slots.  Business Logic for transferring all scheduled jobs existing default Id's to Override Id's
        public int InsertNewTimeSlot(JobTimeSlots model)
        {
            int id            = 0;
            int NewOverrideId = 0;

            DataProvider.ExecuteNonQuery(GetConnection, "dbo.JobTimeSlots_Insert"
                                         , inputParamMapper : delegate(SqlParameterCollection paramCollection)
            {
                paramCollection.AddWithValue("@Date", model.Date);
                paramCollection.AddWithValue("@TimeStart", model.TimeStart);
                paramCollection.AddWithValue("@TimeEnd", model.TimeEnd);
                paramCollection.AddWithValue("@Capacity", model.Capacity);
                paramCollection.AddWithValue("@DefaultId", model.DefaultId);
                paramCollection.AddWithValue("@DayOfWeek", model.DayOfWeek);
                paramCollection.AddWithValue("@TeamId", model.TeamId);
                paramCollection.AddWithValue("@ScheduleType", model.ScheduleType);

                SqlParameter p = new SqlParameter("@Id", System.Data.SqlDbType.Int);
                p.Direction    = System.Data.ParameterDirection.Output;

                paramCollection.Add(p);
            }, returnParameters : delegate(SqlParameterCollection param)
            {
                int.TryParse(param["@Id"].Value.ToString(), out id);
            });

            TimeSlotAvailabilityRequest Availabilities = new TimeSlotAvailabilityRequest();

            NewOverrideId = id;
            //Add If Statement here to grab ONLY Overrides, then do logic for Assuming then a override is added and needs to check if default jobs exist on the same time/date
            if (model.DefaultId != null && model.Date != null && model.ScheduleType == true)
            {
                //Check Availabilities with the Override Info Coming in.  Get Default ID and Check Availabilities that already exist
                Availabilities = CheckExistingDefaultsForOverride(model.Date, model.DefaultId);
                if (Availabilities.CurrentUsed > model.Capacity)
                {
                    //delete the insert in case the capacity is too high
                    DeleteTimeSlot(NewOverrideId);
                    int    OverCapacityAmount = (Availabilities.CurrentUsed - model.Capacity);
                    string message            = "Unable to create Override due to Max Capacity.  Over Amount: " + OverCapacityAmount;
                    throw new System.ArgumentException(message);
                }

                if (Availabilities.CurrentUsed <= model.Capacity)
                {
                    //service to update all ScheduleId to NEW Override Schedule Id
                    UpdateJobScheduleId(NewOverrideId, model.DefaultId, model.Date);
                }
            }
            return(id);
        }