Beispiel #1
0
        public ActionResult AddEvent(DayEventForm dayEventForm, String parameter)
        {
            DateTime startTime = new DateTime(Models.Calendar.getInstance().dateTime.Year, Models.Calendar.getInstance().dateTime.Month, Models.Calendar.getInstance().dateTime.Day, dayEventForm.StartHour, dayEventForm.StartMinute, 1);
            DateTime endTime = new DateTime(Models.Calendar.getInstance().dateTime.Year, Models.Calendar.getInstance().dateTime.Month, Models.Calendar.getInstance().dateTime.Day, dayEventForm.EndHour, dayEventForm.EndMinute, 1);
            startTime = startTime.AddDays(dayEventForm.chosenDayNumber);
            endTime = endTime.AddDays(dayEventForm.chosenDayNumber);

            if (dayEventForm.StartHour > dayEventForm.EndHour)
                return View("AddEvent"); // zdarzenie ma wczesniejszy koniec niz rozpoczecie

            if ((dayEventForm.StartHour == dayEventForm.EndHour) && (dayEventForm.StartMinute > dayEventForm.EndMinute))
                return View("AddEvent"); // zdarzenie ma wczesniejszy koniec niz rozpoczecie

            DayEvent dayEvent = new DayEvent(dayEventForm.Title, dayEventForm.Description, startTime, endTime);

            if (Models.Calendar.getInstance().dayEventsList.BinarySearch(dayEvent, new DayEventsComparer()) >= 0)
                return View("AddEvent");

            Models.Calendar.getInstance().dayEventsList.Add(dayEvent);
            Models.Calendar.getInstance().dayEventsList.Sort(new DayEventsComparer());

            Appointment newAppointment = new Appointment()
            {
                AppointmentID = Guid.NewGuid(),
                Title = dayEventForm.Title,
                Description = dayEventForm.Description,
                AppointmentDate = new DateTime(startTime.Year, startTime.Month, startTime.Day),
                StartTime = new TimeSpan(dayEventForm.StartHour, dayEventForm.StartMinute, 1),
                EndTime = new TimeSpan(dayEventForm.EndHour, dayEventForm.EndMinute, 1)
            };

            Attendance newAttendance = new Attendance()
            {
                AppointmentID = newAppointment.AppointmentID,
                PersonID = Models.Calendar.currentPerson.PersonID,
                Accepted = true,
                AttendanceID = Guid.NewGuid(),
            };

            Models.Calendar.getInstance().databaseContext.Appointments.Add(newAppointment);
            Models.Calendar.getInstance().databaseContext.Attendances.Add(newAttendance);
            Models.Calendar.getInstance().databaseContext.SaveChanges();

            return RedirectToAction("Calendar", "Calendar");  //return View("Calendar", Models.Calendar.getInstance());
        }
Beispiel #2
0
        // **************************************
        // URL: /Calendar/EditEvent.aspx
        // **************************************

        public ActionResult EditEvent(DayEventForm dayEventForm)
        {
            //this.HttpContext.Request.Form["nextWeekButton"]
            //ViewData["message"] = dayEventForm.chosenEventNumber;
            //int chosenDayNumber = (int) RouteData.Values["id"];
            //ViewData["message"] = chosenDayNumber;
            char[] charSeparators = new char[] { ':', '-' };
            string[] separatedStrings;

            String chosenDayEventLabelString = (String)Models.Calendar.getInstance().dayEventLabelsLists[dayEventForm.chosenDayNumber][dayEventForm.chosenEventNumber];
            separatedStrings = chosenDayEventLabelString.Split(charSeparators, StringSplitOptions.None);

            Models.DayEventForm.getInstance().StartHour = Int32.Parse(separatedStrings[0]);
            Models.DayEventForm.getInstance().StartMinute = Int32.Parse(separatedStrings[1]);
            Models.DayEventForm.getInstance().EndHour = Int32.Parse(separatedStrings[2]);
            Models.DayEventForm.getInstance().EndMinute = Int32.Parse(separatedStrings[3]);
            Models.DayEventForm.getInstance().Title = separatedStrings[4];
            Models.DayEventForm.getInstance().Description = separatedStrings[5];
            return View("EditEvent", Models.DayEventForm.getInstance());
        }
Beispiel #3
0
        public ActionResult EditEvent(DayEventForm dayEventForm, String parameter)
        {
            DateTime eventDate = new DateTime(Models.Calendar.getInstance().dateTime.Year, Models.Calendar.getInstance().dateTime.Month, Models.Calendar.getInstance().dateTime.Day);
            eventDate = eventDate.AddDays(dayEventForm.chosenDayNumber);
            DateTime startTime = new DateTime(eventDate.Year, eventDate.Month, eventDate.Day, Models.DayEventForm.getInstance().StartHour, Models.DayEventForm.getInstance().StartMinute, 1);
            DateTime endTime = new DateTime(eventDate.Year, eventDate.Month, eventDate.Day, Models.DayEventForm.getInstance().EndHour, Models.DayEventForm.getInstance().EndMinute, 1);
            TimeSpan previousStartTimeSpan = new TimeSpan(startTime.Hour, startTime.Minute, 1);
            TimeSpan previousEndTimeSpan = new TimeSpan(endTime.Hour, endTime.Minute, 1);
            TimeSpan newStartTimeSpan = new TimeSpan(dayEventForm.StartHour, dayEventForm.StartMinute, 1);
            TimeSpan newEndTimeSpan = new TimeSpan(dayEventForm.EndHour, dayEventForm.EndMinute, 1);
            String previousEventTitle = Models.DayEventForm.getInstance().Title;
            String previousEventDescription = Models.DayEventForm.getInstance().Description;
            String newEventDescription = dayEventForm.Description;
            String newEventTitle = dayEventForm.Title;

            if (dayEventForm.StartHour > dayEventForm.EndHour)
                return View("EditEvent"); // zdarzenie ma wczesniejszy koniec niz rozpoczecie

            if ((dayEventForm.StartHour == dayEventForm.EndHour) && (dayEventForm.StartMinute > dayEventForm.EndMinute))
                return View("EditEvent"); // zdarzenie ma wczesniejszy koniec niz rozpoczecie

            DayEvent chosenDayEvent = new DayEvent(previousEventTitle, previousEventDescription, startTime, endTime);

            if (this.HttpContext.Request.Form["submitButton"] == "Edit event")
            {
                int index = Models.Calendar.getInstance().dayEventsList.BinarySearch(chosenDayEvent, new DayEventsComparer());
                ((DayEvent)Models.Calendar.getInstance().dayEventsList[index]).SetTitle(newEventTitle);
                ((DayEvent)Models.Calendar.getInstance().dayEventsList[index]).SetDescription(newEventDescription);
                ((DayEvent)Models.Calendar.getInstance().dayEventsList[index]).SetStartTime(new DateTime(eventDate.Year, eventDate.Month, eventDate.Day, dayEventForm.StartHour, dayEventForm.StartMinute, 1));
                ((DayEvent)Models.Calendar.getInstance().dayEventsList[index]).SetEndTime(new DateTime(eventDate.Year, eventDate.Month, eventDate.Day, dayEventForm.EndHour, dayEventForm.EndMinute, 1));

                Appointment searchedAppointment;
                Guid appointmentID;

                for (int i = 0; i < Models.Calendar.getInstance().databaseContext.Attendances.Count(); i++)
                {
                    if (Models.Calendar.getInstance().databaseContext.Attendances.AsEnumerable().ElementAt(i).PersonID == Models.Calendar.currentPerson.PersonID)
                    {
                        appointmentID = Models.Calendar.getInstance().databaseContext.Attendances.AsEnumerable().ElementAt(i).AppointmentID;
                        searchedAppointment = Models.Calendar.getInstance().databaseContext.Appointments.FirstOrDefault<Appointment>(
                            appointment => appointment.AppointmentID == appointmentID && appointment.Title == previousEventTitle &&
                            appointment.Description == previousEventDescription && appointment.AppointmentDate == eventDate &&
                            appointment.StartTime.Hours == previousStartTimeSpan.Hours && appointment.StartTime.Minutes == previousStartTimeSpan.Minutes &&
                            appointment.EndTime.Hours == previousEndTimeSpan.Hours && appointment.EndTime.Minutes == previousEndTimeSpan.Minutes);

                        if (searchedAppointment != null)
                        {
                            searchedAppointment.Title = newEventTitle;
                            searchedAppointment.Description = newEventDescription;
                            searchedAppointment.StartTime = newStartTimeSpan;
                            searchedAppointment.EndTime = newEndTimeSpan;
                        }
                    }
                }
                Models.Calendar.getInstance().databaseContext.SaveChanges();
            }
            else if (this.HttpContext.Request.Form["submitButton"] == "Remove event")
            {
                //for(int i = 0; i < )

                int index = Models.Calendar.getInstance().dayEventsList.BinarySearch(chosenDayEvent, new DayEventsComparer());
                Models.Calendar.getInstance().dayEventsList.RemoveAt(index);

                Appointment appointmentToRemove = Models.Calendar.getInstance().databaseContext.Appointments.First<Appointment>(
                        appointment => appointment.Title == previousEventTitle &&
                        appointment.Description == previousEventDescription &&
                        appointment.AppointmentDate == eventDate &&
                        appointment.StartTime.Hours == previousStartTimeSpan.Hours &&
                        appointment.StartTime.Minutes == previousStartTimeSpan.Minutes &&
                        appointment.EndTime.Hours == previousEndTimeSpan.Hours &&
                        appointment.EndTime.Minutes == previousEndTimeSpan.Minutes);

                Attendance attendanceToRemove = Models.Calendar.getInstance().databaseContext.Attendances.First<Attendance>(
                        attendance => attendance.AppointmentID == appointmentToRemove.AppointmentID);

                Models.Calendar.getInstance().databaseContext.Attendances.Remove(attendanceToRemove);
                Models.Calendar.getInstance().databaseContext.Appointments.Remove(appointmentToRemove);
                Models.Calendar.getInstance().databaseContext.SaveChanges();
            }
            return RedirectToAction("Calendar", "Calendar");//return View("EditEvent", dayEventForm); //return View("Calendar", Models.Calendar.getInstance());
        }
Beispiel #4
0
        // **************************************
        // URL: /Calendar/AddEvent.aspx
        // **************************************

        public ActionResult AddEvent(DayEventForm dayEventForm)
        {
            return View("AddEvent");
        }