private void ValidateSubject(SubjectView view) { if (string.IsNullOrEmpty(view.SiteId)) return; var site = _viewDatabase.Sites.FindOneById(view.SiteId); if (site == null) return; var amountOfSubjects = _viewDatabase.Subjects.Count(Query.EQ("SiteId", view.SiteId)); if (site.Capacity <= amountOfSubjects) { ModelState.AddModelError("SiteId", "Capacity limit is reached for selected site. Please select different site."); } }
private SubjectViewModel CreateModel(SubjectView view = null) { view = view ?? new SubjectView(); var model = new SubjectViewModel { SubjectView = view, Sites = _viewDatabase.Sites.FindAll().ToList() }; return model; }