void AddEducationOrganization() { var address = new Address() { Country = Session.DataModel.Countries.FirstOrDefault() }; var eduOrg = new EducationOrganization() { Address = address, EducationOrganizationType = OrgType }; var vm = new EducationOrganizationEditorViewModel(eduOrg); if (DialogLayer.ShowEditor(EditingContent.EducationOrganizationEditor, vm)) { using (var context = new AdmissionDatabase()) { context.Addresses.Add(address); context.EducationOrganizations.Add(eduOrg); context.SaveChanges(); } RefreshOrganizations(); } }
/// <summary> /// Возвращает true при наличии пользователя и инициализирует сессию, открывая контекст доступа к данным /// </summary> /// <param name="username">Имя пользователя</param> /// <param name="password">Пароль</param> public static bool Initialize(string username, string password) { if (_currentUser != null) { throw new InvalidOperationException("Сеанс был инициализирован ранее"); } try { password = Encrypter.MD5Hash(password); var context = new AdmissionDatabase(); var result = (from user in context.Users where user.Username == username && user.PasswordHash == password select user).Single(); _currentUser = result; _accessTime = DateTime.Now; _data = context; return(true); } catch (Exception) { _currentUser = null; _data = null; return(false); } }
void AddCountry() { var country = new Country(); var vm = new CountryEditorViewModel(country); if (DialogLayer.ShowEditor(EditingContent.CountryEditor, vm)) { using (var context = new AdmissionDatabase()) { context.Countries.Add(country); context.SaveChanges(); } RaisePropertyChanged("Countries"); } }
/// <summary> /// Записывает отчетную информацию в журнал операций, добавляя текущее время /// </summary> /// <param name="logMessage">Текст отчетного сообщения</param> public static void WriteLog(string logMessage) { using (var context = new AdmissionDatabase()) { var log = new Log { Date = DateTime.Now.Date, Time = DateTime.Now.TimeOfDay, UserId = Session.CurrentUser.Id, Message = logMessage }; context.Logs.Add(log); context.SaveChanges(); } }
void AddRegion() { var region = new Region(); region.CountryId = Country.Id; var vm = new RegionEditorViewModel(region); if (DialogLayer.ShowEditor(EditingContent.RegionEditor, vm)) { using (var context = new AdmissionDatabase()) { context.Regions.Add(region); context.SaveChanges(); Region = region; } RefreshRegions(); } }
void AddLocality() { var locality = new Locality(); locality.DistrictId = District.Id; var vm = new LocalityEditorViewModel(locality); if (DialogLayer.ShowEditor(EditingContent.LocalityEditor, vm)) { using (var context = new AdmissionDatabase()) { context.Localities.Add(locality); context.SaveChanges(); Locality = locality; } RefreshLocalities(); } }
void AddDistrict() { var district = new District(); district.RegionId = Region.Id; var vm = new DistrictEditorViewModel(district); if (DialogLayer.ShowEditor(EditingContent.DistrictEditor, vm)) { using (var context = new AdmissionDatabase()) { context.Districts.Add(district); context.SaveChanges(); District = district; } RefreshDistricts(); } }
void AddStreet() { var street = new Street(); if (Town != null) { street.ParentID = Town.Id; var vm = new StreetFromTownEditorViewModel(street); if (DialogLayer.ShowEditor(EditingContent.StreetFromTownEditor, vm)) { using (var context = new AdmissionDatabase()) { context.Streets.Add(street); context.SaveChanges(); RefreshStreetsFromTown(); Street = street; } } } else { if (Locality != null) { street.ParentID = Locality.Id; var vm = new StreetFromLocalityEditorViewModel(street); if (DialogLayer.ShowEditor(EditingContent.StreetFromLocalityEditor, vm)) { using (var context = new AdmissionDatabase()) { context.Streets.Add(street); context.SaveChanges(); RefreshStreetsFromLocality(); Street = street; } } } } }
void AddTown() { var town = new Town(); town.RegionId = Region.Id; var vm = new TownEditorViewModel(town); if (DialogLayer.ShowEditor(EditingContent.TownEditor, vm)) { using (var context = new AdmissionDatabase()) { context.Towns.Add(town); context.SaveChanges(); District = null; Locality = null; Street = null; RefreshTowns(); Town = town; } } }