/// <summary>
        /// Written: 18/11/2012
        /// This method passes all the appropriate information into an event which can be 
        /// viewed and edited through the client software.
        /// </summary>
        /// <param name="eventTitle"></param>
        /// <param name="userId"></param>
        /// <param name="eventDescription"></param>
        /// <param name="eventType"></param>
        /// <param name="repeatType"></param>
        /// <param name="eventDuration"></param>
        /// <param name="startDate"></param>
        /// <param name="eventTime"></param>
        /// <param name="roomName"></param>
        /// <param name="courseName"></param>
        /// <param name="moduleName"></param>
        /// <returns></returns>
        public int CreateEvent(string eventTitle, int userId, string eventDescription, string eventType,
            string repeatType, int eventDuration, DateTime startDate, string eventTime, string roomName,
            string courseName, string moduleName)
        {
            //Id generated
            var generatedEventId = EventIdGeneration();

            //If id value continue if not return 0
            if (generatedEventId == 0)
            {
                return 0;
            }
            //repeat Id set to default if repeats not implemented
            var repeatId = 0;

            //repeat type retunred repeat id set withni the event object
            var repeat = _dBase.RepeatTypes.SingleOrDefault(x => x.RepeatTypeName == repeatType);
            if (repeatType != "0" && repeat != null)
            {
                repeatId = repeat.RepeatTypeId;
            }

            var roomId = 0;
            //default room is 0 unless a room has been passed in from the client
            var room = _dBase.Rooms.SingleOrDefault(x => x.RoomName == roomName);
            if (roomName != "0" && room != null)
            {
                roomId = room.RoomId;
            }

            var timeId = 0;
            //time is by default 0 if time is not passed in (not possible in cleint however)
            var time = _dBase.Times.SingleOrDefault(x => x.TimeLiteral == eventTime);
            if (eventTime != "0" && time != null)
            {
                timeId = time.TimeId;
            }

            var courseId = 0;
            //course by default set to 0 unless passed in by client
            var course = _dBase.Courses.SingleOrDefault(x => x.CourseName == courseName);
            if (courseName != "0" && course != null)
            {
                courseId = course.CourseId;
            }

            var moduleId = 0;
            var module = _dBase.Modules.SingleOrDefault(x => x.ModuleName == moduleName);
            //module by default set to 0 unless passed in by client
            if (moduleName != "0" && module != null)
            {
                moduleId = module.ModuleId;
                //Module Event generated by ModuleEvent method
                ModuleEvent(generatedEventId, moduleId, courseId);
            }

            var typeId = 0;
            //event type is by default 0 if time is not passed in (not possible in cleint however)
            var type = _dBase.EventTypes.SingleOrDefault(x => x.TypeName == eventType);
            if (eventType != "0" && type != null)
            {
                typeId = type.TypeId;
            }
            //event object created too be adde to the databse
            var newEvent = new Event
            {
                EventId = generatedEventId,
                EventTitle = eventTitle,
                EventType = typeId,
                EventDescription = eventDescription,
                Repeats = repeatId,
                Duration = eventDuration,
                CreateDate = DateTime.Now,
                Status = "New",
                StartDate = startDate,
                LastDateEdited = DateTime.Now,
                Time = timeId,
                Room = roomId,
                AdditionalNotes = "None",
                LastUserEdited = userId,
                Module = moduleId,
                Course = courseId
            };
            //event added to the databse
            _dBase.Events.Add(newEvent);
            _dBase.SaveChanges();
            //id of generate event returned
            return generatedEventId;
        }
        /// <summary>
        /// Written: 18/11/2012
        /// This method passes all the appropriate information into an event which can be 
        /// viewed and edited through the client software.
        /// </summary>
        /// <param name="eventTitle"></param>
        /// <param name="eventDescription"></param>
        /// <param name="eventType"></param>
        /// <param name="eventDate"></param>
        /// <param name="eventTime"></param>
        /// <param name="eventDuration"></param>
        /// <param name="eventRepeats"></param>
        /// <returns></returns>
        public int CreateEvent(string eventTitle, int userId, string eventDescription, string eventType, string repeatType, int eventDuration, DateTime startDate, string eventTime, string roomName, string courseName, string moduleName)
        {
            var generatedEventId = EventIdGeneration();

                if (generatedEventId == 0)
                {
                    return 0;
                }

                var repeatId = db.RepeatTypes.SingleOrDefault(x=>x.RepeatTypeName == repeatType).RepeatTypeId;
                var timeId = db.Times.SingleOrDefault(x => x.TimeLiteral == eventTime).TimeId;
                var roomId = db.Rooms.SingleOrDefault(x=>x.RoomName == roomName).RoomId;
                var courseId = db.Courses.SingleOrDefault(x => x.CourseName == courseName).CourseId;
                var moduleId = db.Modules.SingleOrDefault(x => x.ModuleName == moduleName).ModuleId;
                var typeId = db.EventTypes.SingleOrDefault(x => x.TypeName == eventType).TypeId;

                var newEvent = new Event()
                {
                    EventId = generatedEventId,
                    EventTitle = eventTitle,
                    EventType = typeId,
                    EventDescription = eventDescription,
                    Repeats = repeatId,
                    Duration = eventDuration,
                    CreateDate = DateTime.Now,
                    Status = "New",
                    StartDate = startDate,
                    LastDateEdited = DateTime.Now,
                    Time = timeId,
                    Room = roomId,
                    AdditionalNotes = "None",
                    LastUserEdited = userId,
                    Module = moduleId,
                    Course = courseId
                };

                db.Events.Add(newEvent);
                db.SaveChanges();

                return generatedEventId;
        }
Exemplo n.º 3
0
 /// <summary>
 /// returns event details associated with id passed in from website
 /// </summary>
 /// <param name="eventId"></param>
 /// <returns></returns>
 public Event ReturnEventDetail(int eventId)
 {
     //default evet declared
     var none = new Event();
     //selection of event by event Id passed in
     var temp = _db.Events.SingleOrDefault(x => x.EventId == eventId);
     if (temp != null)
     {
         //event returned
         return temp;
     }
     //empty event returned
     return none;
 }