示例#1
0
        public string Save(AllocateClassRoom allocateClassRoom)
        {
            var allocateClassRoomInfo = allocateClassRoomGateway.GetAllocateInfoByDayAndRoomId(allocateClassRoom.DayId,
                                                                                               allocateClassRoom.RoomId);
            bool notAllowed = false;

            if (allocateClassRoomInfo != null)
            {
                foreach (AllocateClassRoom info in allocateClassRoomInfo)
                {
                    DateTime dbFromTime = DateTime.Parse(info.FromTime);
                    DateTime dbToTime   = DateTime.Parse(info.ToTime);
                    DateTime fromTime   = DateTime.Parse(allocateClassRoom.FromTime);
                    DateTime toTime     = DateTime.Parse(allocateClassRoom.ToTime);
                    if ((fromTime >= dbFromTime && toTime <= dbToTime) || (fromTime < dbFromTime && toTime >= dbToTime) ||
                        (fromTime < dbFromTime && (toTime > dbFromTime && toTime <= dbToTime)) || (fromTime >= dbFromTime && fromTime < dbToTime) && toTime >= dbToTime)
                    {
                        notAllowed = true;
                    }
                }
            }
            if (notAllowed)
            {
                return("Classroom already scheduled in selected time! Choose another time period");
            }
            else
            {
                int rowAffected = allocateClassRoomGateway.Save(allocateClassRoom);
                if (rowAffected > 0)
                {
                    return("Class Room Allocated!");
                }
                return("Failed to allocated class room");
            }
        }
示例#2
0
 public string Save(AllocateClassRoom allocateClassRoom)
 {
     if (allocateClassRoomGateway.Save(allocateClassRoom) > 0)
     {
         return("The class room allocated successfully.");
     }
     return("Failed to allocate the class room.");
 }
示例#3
0
        public string Save(AllocateClassroom allocateClassroom)
        {
            int rowaffect = allocateClassroomsGateway.Save(allocateClassroom);

            if (rowaffect > 0)
            {
                return("Save successful");
            }
            else
            {
                return("Save Failed");
            }
        }
 public bool Save(AllocateClassroom allocateClassroom)
 {
     return(_allocateClassRoomGateway.Save(allocateClassroom));
 }
        public string Save(AllocateClassRoom allocateClassRoom)
        {
            List <AllocateClassRoom> classRoomAllocations =
                allocateClassRoomGateway.GetClassRoomAllocationInfo(allocateClassRoom.RoomId, allocateClassRoom.Day);

            //int rowAffected = allocateClassRoomGateway.Save(allocateClassRoom);
            //if (classRoomAllocations.Count == 0)
            //{
            //    int rowAffected = allocateClassRoomGateway.Save(allocateClassRoom);
            //    if (rowAffected > 0)
            //    {
            //        return "Success";
            //    }
            //    else
            //    {
            //        return "Failed.";
            //    }
            //}

            //else
            //{
            //    return "Room Can't be allocated.";
            //}

            {
                string   fromTime           = allocateClassRoom.FromTimeHour + " " + allocateClassRoom.FromTimePeriod;
                string   toTime             = allocateClassRoom.ToTimeHour + " " + allocateClassRoom.ToTimePeriod;
                string   dateFormat         = "h:mm tt";
                DateTime fromDateTime       = DateTime.ParseExact(fromTime, dateFormat, CultureInfo.InvariantCulture);
                DateTime toDateTime         = DateTime.ParseExact(toTime, dateFormat, CultureInfo.InvariantCulture);
                bool     roomCanBeAllocated = true;


                if ((TimeSpan.Compare(toDateTime.TimeOfDay, fromDateTime.TimeOfDay) == 0))
                {
                    roomCanBeAllocated = false;
                }
                else
                {
                    foreach (AllocateClassRoom classRoom in classRoomAllocations)
                    {
                        DateTime fromTimeExist = DateTime.ParseExact(classRoom.FromTime, dateFormat,
                                                                     CultureInfo.InvariantCulture);
                        DateTime toTimeExist = DateTime.ParseExact(classRoom.ToTime, dateFormat,
                                                                   CultureInfo.InvariantCulture);
                        if ((TimeSpan.Compare(fromTimeExist.TimeOfDay, fromDateTime.TimeOfDay) == 1 &&
                             TimeSpan.Compare(fromTimeExist.TimeOfDay, toDateTime.TimeOfDay) == 1)
                            ||
                            (TimeSpan.Compare(toTimeExist.TimeOfDay, fromDateTime.TimeOfDay) == -1 &&
                             TimeSpan.Compare(toTimeExist.TimeOfDay, toDateTime.TimeOfDay) == -1)
                            ||
                            (TimeSpan.Compare(toTimeExist.TimeOfDay, fromDateTime.TimeOfDay) == 0 &&
                             TimeSpan.Compare(toTimeExist.TimeOfDay, toDateTime.TimeOfDay) == -1)
                            ||
                            (TimeSpan.Compare(fromTimeExist.TimeOfDay, toDateTime.TimeOfDay) == 0 &&
                             TimeSpan.Compare(fromTimeExist.TimeOfDay, fromDateTime.TimeOfDay) == 1)
                            )
                        {
                            roomCanBeAllocated = true;
                        }
                        //else if ((TimeSpan.Compare(toDateTime.TimeOfDay, fromDateTime.TimeOfDay) == 0))
                        //{
                        //    roomCanBeAllocated = false;
                        //    break;
                        //}
                        else
                        {
                            roomCanBeAllocated = false;
                        }
                    }
                }


                if (roomCanBeAllocated)
                {
                    int rowAffected = allocateClassRoomGateway.Save(allocateClassRoom);
                    if (rowAffected > 0)
                    {
                        return("Room Successfully Allocated.");
                    }
                    else
                    {
                        return("Room Can't be allocated.");
                    }
                }
                else
                {
                    return("Room Can't be allocated.");
                }
            }
        }