public CMSResult Save(StudentTimetable studentTimetable)
        {
            CMSResult result   = new CMSResult();
            var       isExists = _repository.Project <StudentTimetable, bool>(studentTimetables => (
                                                                                  from p in studentTimetables
                                                                                  where p.Description == studentTimetable.Description && p.Category == studentTimetable.Category
                                                                                  select p
                                                                                  ).Any());

            if (isExists)
            {
                result.Results.Add(new Result {
                    IsSuccessful = false, Message = string.Format("Time table '{0}' already exists !", studentTimetable.Description)
                });
            }
            else
            {
                _repository.Add(studentTimetable);
                _repository.CommitChanges();
                result.Results.Add(new Result {
                    IsSuccessful = true, Message = string.Format("Time Table added successfully!")
                });
            }
            return(result);
        }
        public CMSResult Update(StudentTimetable oldTimeTable)
        {
            CMSResult result   = new CMSResult();
            var       isExists = _repository.Project <StudentTimetable, bool>(timetables =>
                                                                              (from timeTable in timetables
                                                                               where timeTable.StudentTimetableId != oldTimeTable.StudentTimetableId && timeTable.Description == oldTimeTable.Description && timeTable.Category == oldTimeTable.Category
                                                                               select timeTable).Any());

            if (isExists)
            {
                result.Results.Add(new Result {
                    IsSuccessful = false, Message = string.Format("Time table already exists!", "")
                });
            }
            else
            {
                var timetable = _repository.Load <StudentTimetable>(x => x.StudentTimetableId == oldTimeTable.StudentTimetableId);
                timetable.Description           = oldTimeTable.Description;
                timetable.AttachmentDescription = oldTimeTable.AttachmentDescription;
                timetable.StudentTimetableDate  = oldTimeTable.StudentTimetableDate;
                timetable.FileName = oldTimeTable.FileName;
                _repository.Update(timetable);
                result.Results.Add(new Result {
                    IsSuccessful = true, Message = string.Format("Time table successfully updated!", "")
                });
            }
            return(result);
        }
        public ActionResult DeleteConfirmed(int id)
        {
            StudentTimetable studentTimetable = db.StudentTimetables.Find(id);

            db.StudentTimetables.Remove(studentTimetable);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Пример #4
0
        public void ShowTimetableView(StudentTimetable timetable, Day startDay)
        {
            if (startDay == null)
            {
                if (StartDay != null)
                {
                    startDay = StartDay;
                }
                else
                {
                    startDay = Day.Today;
                }
            }
            if (timetable == null)
            {
                if (Timetable != null)
                {
                    timetable = Timetable;
                }
                else
                {
                    return;
                }
            }

            TimetableView timetableView = new TimetableView(Activity, timetable, startDay, this);

            SetContentView(timetableView);

            IsLoading = false;
            Timetable = timetable;
            StartDay  = startDay;

            ShowOptionMenu(true);

            var settings = Activity.GetSharedPreferences(PreferencesFile, FileCreationMode.Private);

            var studentIdHistory = JsonValue.Parse(settings.GetString(StudentIdHistory, "[]")).Cast <int>().ToList();

            studentIdHistory.Insert(0, Timetable.Student.Id);

            var settingsEditor = settings.Edit();

            settingsEditor.PutInt(StudentId, Timetable.Student.Id);
            //settingsEditor.PutString(StudentIdHistory, new JsonArray(studentIdHistory).ToString());
            settingsEditor.Commit();

            Day currentDay = startDay;

            for (int i = 0; i < PreloadDays; i++)
            {
                Timetable.UpdateIfNeeded(currentDay, (day, events) => {}, e => Console.WriteLine(e));
                currentDay = MultiDayView.GetFirstValidDay(currentDay, 1);
            }
        }
        // GET: StudentTimetables/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            StudentTimetable studentTimetable = db.StudentTimetables.Find(id);

            if (studentTimetable == null)
            {
                return(HttpNotFound());
            }
            return(View(studentTimetable));
        }
Пример #6
0
 private void LoadTimetableUsingStudentId(int studentId)
 {
     ShowLoadingView();
     Timetable        = null;
     CurrentStudentId = studentId;
     StudentTimetable.Load.AsyncInvoke(studentId, ShowTimetableView, e =>
     {
         Console.WriteLine(e);
         GetNewStudentId("Er is een fout opgetreden bij het ophalen "
                         + "van het rooster voor dit studentnummer:\n\n"
                         + e.ToShortString() + "\n\n"
                         + "Controleer aub of het ingevoerde nummer klopt.",
                         studentId.ToString());
     });
 }
        public ActionResult Create(StudentTimetableViewModel viewModel)
        {
            var roleUserId = User.Identity.GetUserId();
            var roles      = _aspNetRolesService.GetCurrentUserRole(roleUserId);
            var cmsResult  = new CMSResult();

            if (ModelState.IsValid)
            {
                string fileName = "";
                Guid   guid     = Guid.NewGuid();
                if (viewModel.FilePath != null)
                {
                    if (viewModel.AttachmentDescription == null)
                    {
                        _logger.Warn("Please enter attachment description.");
                        Warning("Please enter attachment description.", true);
                        ReturnViewModel(viewModel, roles, roleUserId);
                        return(View(viewModel));
                    }
                    else if (Common.Constants.ImageTypes.Contains(viewModel.FilePath.ContentType) ||
                             Common.Constants.PdfType.Contains(viewModel.FilePath.ContentType))
                    {
                        if (viewModel.FilePath != null)
                        {
                            if (Common.Constants.ImageTypes.Contains(viewModel.FilePath.ContentType))
                            {
                                fileName = string.Format("{0}.jpg", guid);
                            }
                            else
                            {
                                fileName = string.Format("{0}.pdf", guid);
                            }
                        }
                    }
                    else
                    {
                        _logger.Warn("Please choose either a JPEG, JPG, PNG image or pdf file.");
                        Warning("Please choose either a JPEG, JPG, PNG image or pdf file", true);
                        ReturnViewModel(viewModel, roles, roleUserId);
                        return(View(viewModel));
                    }
                }
                var description = viewModel.Description.Replace("\r\n", "<br />");
                viewModel.Description = description;
                var studentClassTimetable = new StudentTimetable
                {
                    Description           = viewModel.Description,
                    SelectedBranches      = viewModel.SelectedBranches != null ? viewModel.SelectedBranches : "",
                    SelectedClasses       = viewModel.SelectedClasses != null ? viewModel.SelectedClasses : "",
                    SelectedBatches       = viewModel.SelectedBatches != null ? viewModel.SelectedBatches : "",
                    FileName              = fileName,
                    Category              = Common.Enums.TimetableCategory.ClassTimetable,
                    AttachmentDescription = viewModel.AttachmentDescription != null ? viewModel.AttachmentDescription : "",
                    StudentTimetableDate  = viewModel.StudentTimetableDate
                };
                var result = _studentTimetableService.Save(studentClassTimetable);

                if (result.Success)
                {
                    var studentClassTimetableId = studentClassTimetable.StudentTimetableId;

                    if (viewModel.FilePath != null)
                    {
                        var    pathToSaveQI = "";
                        string folderPath   = Server.MapPath(string.Concat("~/PDF/", Common.Constants.StudentTimeTableFile));
                        if (!Directory.Exists(folderPath))
                        {
                            Directory.CreateDirectory(folderPath);
                        }

                        if (Common.Constants.ImageTypes.Contains(viewModel.FilePath.ContentType))
                        {
                            pathToSaveQI = Path.Combine(folderPath, string.Format("{0}.jpg", guid));
                        }
                        else
                        {
                            pathToSaveQI = Path.Combine(folderPath, string.Format("{0}.pdf", guid));
                        }

                        if (viewModel.FilePath != null)
                        {
                            viewModel.FilePath.SaveAs(pathToSaveQI);
                        }
                    }

                    var sendAppNotification = SendAppNotification(viewModel, studentClassTimetableId);

                    if (roles == "BranchAdmin")
                    {
                        SendTimetable(viewModel);
                    }

                    Success(result.Results.FirstOrDefault().Message + "<br />" + sendAppNotification.Results[0].Message);
                    ModelState.Clear();
                    viewModel = new StudentTimetableViewModel();
                }
                else
                {
                    _logger.Warn(result.Results.FirstOrDefault().Message);
                    Warning(result.Results.FirstOrDefault().Message, true);
                }
            }
            ReturnViewModel(viewModel, roles, roleUserId);
            return(View(viewModel));
        }
Пример #8
0
 private void timetableForm_SaveExistingStudentTimetable(StudentTimetable studentTimetable)
 {
     studentTimetableList[lessonsListBox.SelectedIndex] = studentTimetable;
 }
Пример #9
0
 private void timetableForm_SaveNewStudentTimetable(StudentTimetable studentTimetable)
 {
     studentTimetableList.Add(studentTimetable);
     lessonsListBox.Items.Add("Lesson " + studentTimetableList.Count.ToString());
 }
Пример #10
0
 public void ShowTimetableView(StudentTimetable timetable)
 {
     ShowTimetableView(timetable, null);
 }
 public ActionResult Edit(StudentTimetable studentTimetable)
 {
     db.Entry(studentTimetable).State = EntityState.Modified;
     // db.SaveChanges();
     return(RedirectToAction("Index"));
 }
 public ActionResult Create(StudentTimetable studentTimetable)
 {
     db.StudentTimetables.Add(studentTimetable);
     db.SaveChanges();
     return(RedirectToAction("Index"));
 }