Esempio n. 1
0
        public static UserFacilitySchedulingModel ToModel(this UserFacilitySchedulingViewModel entity)
        {
            if (entity == null)
            {
                return(null);
            }

            var model = new UserFacilitySchedulingModel
            {
                DayOfWeekID              = entity.DayOfWeekID,
                Days                     = entity.Days,
                ScheduleTypeID           = entity.ScheduleTypeID,
                UserFacilityTimeSchedule = new List <UserFacilityTimeSchedulingModel>(),
                ModifiedOn               = entity.ModifiedOn
            };

            if (entity.UserFacilityTimeSchedule != null)
            {
                entity.UserFacilityTimeSchedule.ForEach(delegate(UserFacilityTimeSchedulingViewModel userFacilityTime)
                {
                    var transformedModel = userFacilityTime.ToModel();
                    model.UserFacilityTimeSchedule.Add(transformedModel);
                });
            }

            return(model);
        }
Esempio n. 2
0
        public Response <UserSchedulingModel> GetUserFacilities(int userID)
        {
            var repository = _unitOfWork.GetRepository <UserFacilitySchedulingDataModel>(SchemaName.Scheduling);
            var procParams = new List <SqlParameter> {
                new SqlParameter("ResourceID", userID),
                new SqlParameter("ResourceTypeID", 2)
            };
            var userFacilitiesResult = repository.ExecuteStoredProc("usp_GetResourceAvailability", procParams);

            var result = userFacilitiesResult.CloneResponse <UserSchedulingModel>();

            result.ID = userID;
            if (result.ResultCode != 0)
            {
                return(result);
            }

            result.DataItems = new List <UserSchedulingModel>();

            var groupByFacilities = from userFacility in userFacilitiesResult.DataItems
                                    group userFacility by userFacility.FacilityID;

            foreach (var groupFacility in groupByFacilities)
            {
                var userFacility = new UserSchedulingModel();
                userFacility.FacilityID = groupFacility.Key;

                var groupByDays = groupFacility.GroupBy(x => x.DayOfWeekID);

                foreach (var groupByDay in groupByDays)
                {
                    var userFacilityScheduling = new UserFacilitySchedulingModel();
                    userFacilityScheduling.DayOfWeekID = groupByDay.Key;
                    foreach (var item in groupByDay)
                    {
                        userFacilityScheduling.Days = item.Days;
                        var userFacilityTimeScheduling = new UserFacilityTimeSchedulingModel();
                        userFacilityTimeScheduling.ResourceAvailabilityID = item.ResourceAvailabilityID;
                        userFacilityTimeScheduling.AvailabilityStartTime  = item.AvailabilityStartTime;
                        userFacilityTimeScheduling.AvailabilityEndTime    = item.AvailabilityEndTime;
                        userFacilityScheduling.UserFacilityTimeSchedule.Add(userFacilityTimeScheduling);
                    }
                    userFacility.UserFacilitySchedule.Add(userFacilityScheduling);
                }

                userFacility.UserFacilitySchedule = userFacility.UserFacilitySchedule.OrderBy(x => x.DayOfWeekID).ToList();
                result.DataItems.Add(userFacility);
            }

            return(result);
        }
        public void SaveUserFacilitySchedule_Success()
        {
            var url = baseRoute + "SaveUserFacilitySchedule";

            var scheduleMonday = new UserFacilitySchedulingModel {
                FacilityID               = 3,
                DayOfWeekID              = 1,
                ScheduleTypeID           = 4,
                UserFacilityTimeSchedule = new  List <UserFacilityTimeSchedulingModel> {
                    new  UserFacilityTimeSchedulingModel {
                        ResourceAvailabilityID = 0, AvailabilityStartTime = "0800", AvailabilityEndTime = "1200"
                    },
                    new  UserFacilityTimeSchedulingModel {
                        ResourceAvailabilityID = 0, AvailabilityStartTime = "1300", AvailabilityEndTime = "1200"
                    }
                }
            };

            var scheduleTuesday = new UserFacilitySchedulingModel {
                FacilityID               = 3,
                DayOfWeekID              = 2,
                ScheduleTypeID           = 4,
                UserFacilityTimeSchedule = new  List <UserFacilityTimeSchedulingModel> {
                    new  UserFacilityTimeSchedulingModel {
                        ResourceAvailabilityID = 0, AvailabilityStartTime = "0800", AvailabilityEndTime = "1200"
                    },
                    new  UserFacilityTimeSchedulingModel {
                        ResourceAvailabilityID = 0, AvailabilityStartTime = "1300", AvailabilityEndTime = "1200"
                    }
                }
            };

            var userSchedulingModel = new UserSchedulingModel
            {
                FacilityID           = 3,
                ResourceID           = 1,
                UserFacilitySchedule = new List <UserFacilitySchedulingModel> {
                    scheduleMonday, scheduleTuesday
                }
            };

            var response = communicationManager.Post <UserSchedulingModel, Response <UserSchedulingModel> >(userSchedulingModel, url);

            Assert.IsTrue(response != null, "Response can't be null");
            Assert.IsTrue(response.ResultCode == 0, "Result Code must be 0");
        }
Esempio n. 4
0
        public static UserFacilitySchedulingViewModel ToViewModel(this UserFacilitySchedulingModel entity)
        {
            if (entity == null)
            {
                return(null);
            }

            var model = new UserFacilitySchedulingViewModel
            {
                DayOfWeekID              = entity.DayOfWeekID,
                Days                     = entity.Days,
                ScheduleTypeID           = (entity.ScheduleTypeID != null) ? entity.ScheduleTypeID : 4,
                UserFacilityTimeSchedule = new List <UserFacilityTimeSchedulingViewModel>(),
                ModifiedOn               = entity.ModifiedOn
            };

            if (entity.UserFacilityTimeSchedule != null)
            {
                var rowNum = 0;
                entity.UserFacilityTimeSchedule.ForEach(delegate(UserFacilityTimeSchedulingModel userFacilityTime)
                {
                    var transformedModel       = userFacilityTime.ToViewModel();
                    transformedModel.RowNumber = rowNum;
                    transformedModel.IsActive  = true;
                    rowNum++;
                    model.UserFacilityTimeSchedule.Add(transformedModel);
                });
            }

            model.RowCount = model.UserFacilityTimeSchedule.Any() ? model.UserFacilityTimeSchedule.Count() : 1;
            var firstUserFacilityTime = model.UserFacilityTimeSchedule.FirstOrDefault();

            if (firstUserFacilityTime != null)
            {
                firstUserFacilityTime.IsFirst = true;
            }

            var lastUserFacilityTime = model.UserFacilityTimeSchedule.LastOrDefault();

            if (lastUserFacilityTime != null)
            {
                lastUserFacilityTime.IsLast = true;
            }

            return(model);
        }
Esempio n. 5
0
        public Response <UserSchedulingModel> GetUserFacilitySchedule(int userID, int facilityID)
        {
            var result = new Response <UserSchedulingModel>();

            result.ResultCode = 0;

            var dataItem = new List <UserSchedulingModel>();
            var model    = new UserSchedulingModel();

            model.FacilityID = facilityID;

            var repository = _unitOfWork.GetRepository <UserFacilitySchedulingDataModel>(SchemaName.Scheduling);
            var procParams = new List <SqlParameter> {
                new SqlParameter("ResourceID", userID),
                new SqlParameter("ResourceTypeID", 2),
                new SqlParameter("FacilityID", facilityID)
            };
            var userFacilitiesResult = repository.ExecuteStoredProc("usp_GetResourceAvailabilityByFacilityID", procParams);

            var groupByuserFacilities = userFacilitiesResult.DataItems.GroupBy(x => x.DayOfWeekID);

            foreach (var groupByuserFacility in groupByuserFacilities)
            {
                var userFacilityScheduling = new UserFacilitySchedulingModel();
                userFacilityScheduling.DayOfWeekID = groupByuserFacility.Key;
                foreach (var item in groupByuserFacility)
                {
                    userFacilityScheduling.Days           = item.Days;
                    userFacilityScheduling.ScheduleTypeID = item.ScheduleTypeID;
                    var userFacilityTimeScheduling = new UserFacilityTimeSchedulingModel();
                    userFacilityTimeScheduling.ResourceAvailabilityID = item.ResourceAvailabilityID;
                    userFacilityTimeScheduling.AvailabilityStartTime  = item.AvailabilityStartTime;
                    userFacilityTimeScheduling.AvailabilityEndTime    = item.AvailabilityEndTime;
                    userFacilityScheduling.UserFacilityTimeSchedule.Add(userFacilityTimeScheduling);
                }
                model.UserFacilitySchedule.Add(userFacilityScheduling);
            }

            if (model.UserFacilitySchedule != null)
            {
                model.UserFacilitySchedule = model.UserFacilitySchedule.OrderBy(x => x.DayOfWeekID).ToList();
            }

            var repositoryFacility = _unitOfWork.GetRepository <UserFacilitySchedulingDataModel>(SchemaName.Scheduling);
            var procParamsFacility = new List <SqlParameter> {
                new SqlParameter("ResourceID", DBNull.Value),
                new SqlParameter("ResourceTypeID", 6),
                new SqlParameter("FacilityID", facilityID)
            };
            var facilityScheduleResult = repositoryFacility.ExecuteStoredProc("usp_GetResourceAvailabilityByFacilityID", procParamsFacility);

            var groupByFacilities = facilityScheduleResult.DataItems.GroupBy(x => x.DayOfWeekID);

            foreach (var groupByFacility in groupByFacilities)
            {
                var facilityScheduling = new UserFacilitySchedulingModel();
                facilityScheduling.DayOfWeekID = groupByFacility.Key;
                foreach (var item in groupByFacility)
                {
                    facilityScheduling.Days = item.Days;
                    var facilityTimeScheduling = new UserFacilityTimeSchedulingModel();
                    facilityTimeScheduling.ResourceAvailabilityID = item.ResourceAvailabilityID;
                    facilityTimeScheduling.AvailabilityStartTime  = item.AvailabilityStartTime;
                    facilityTimeScheduling.AvailabilityEndTime    = item.AvailabilityEndTime;
                    facilityScheduling.UserFacilityTimeSchedule.Add(facilityTimeScheduling);
                }
                model.FacilitySchedule.Add(facilityScheduling);
            }

            if (model.FacilitySchedule != null)
            {
                model.FacilitySchedule = model.FacilitySchedule.OrderBy(x => x.DayOfWeekID).ToList();
            }

            dataItem.Add(model);
            result.DataItems = dataItem;

            return(result);
        }