private void SaveParent(Parent parent) { var person = parent.Person; var foundParent = _allParents.FirstOrDefault(p => p.Person.FirstName == person.FirstName && p.Person.LastName == person.LastName && p.Person.Patronymic == person.Patronymic); if (foundParent != null) { var res = MessageBox.Show("Родитель с такими ФИО уже существует. Добавить нового?", "Добавление родителя", MessageBoxButton.YesNo); if (res != MessageBoxResult.Yes) { return; } } var context = new KindergartenContext(); context.Parents.Add(parent); try { context.SaveChanges(); Pipe.SetParameter("parent_result", parent); Finish(); } catch (Exception e) { MessageBox.Show(e.Message, "Ошибка"); } }
private void UpdateParents() { var context = new KindergartenContext(); _allParents = context.Parents.Include("Person").ToList(); Parents = new ListCollectionView(_allParents); }
static void Main() { // EFlogger.EntityFramework6.EFloggerFor6.Initialize(); var k = new KindergartenContext(); var list = k.Children.ToList(); Console.WriteLine(list.Count); }
// ReSharper disable once UnusedMember.Local private static ParentChild AddParentChild(KindergartenContext k) { var group = new Group { Name = "Солнышко", GroupType = Groups.Nursery, }; // k.Groups.Add(group); var child = new Child { Person = new Person { FirstName = "Иван", LastName = "Иванов", Patronymic = "Иванович", }, BirthDate = new DateTime(2014, 1, 4), Group = @group, LocationAddress = "ул. Ленина д. 12", Sex = Sex.Male, }; // k.Children.Add(child); var parent = new Parent { LocationAddress = "ул. Ленина д. 12", ResidenceAddress = "ул. Ленина д. 12", WorkAddress = "ул. Ленина д. 73", PassportIssueDate = new DateTime(1990, 04, 12), PassportIssuedBy = "ОУФМС России по р. ХХХ", PassportSeries = "0123456789", PhoneNumber = "+7 912 345 67 89", Person = new Person { FirstName = "Сергей", LastName = "Иванов", Patronymic = "Васильевич", }, }; // k.Parents.Add(parent); var parentChild = new ParentChild { Child = child, Parent = parent, ParentType = Parents.Father, }; k.ParentChildren .Add(parentChild); return(parentChild); }
private async void ChangeGroupType() { ChangeGroupTypeCommand.NotifyCanExecute(false); var groupType = await Task.Run(() => { var context = new KindergartenContext(); var group = context.Groups.First(g => g.Id == CurrentGroup.Id); group.GroupType = SelectedGroupType | (CurrentGroup.GroupType & Groups.Finished); // save Finished flag context.SaveChanges(); return(group.GroupType); }); Pipe.SetParameter("group_type_result", groupType); ChangeGroupTypeCommand.NotifyCanExecute(true); Finish(); }
private static Group RemoveFirstParentChildPairWithPeople(KindergartenContext k) { var pair = k.ParentChildren .Include("Child.Group") .Include("Parent") .Include("Child.Person") .Include("Parent.Person") .First(); var group = pair.Child.Group; var cperson = pair.Child.Person; var pperson = pair.Parent.Person; k.People.Remove(cperson); k.People.Remove(pperson); return(group); }
private async void AddGroup(Group group) { if (!group.IsValid()) { return; } AddGroupCommand.NotifyCanExecute(false); await Task.Run(() => { var context = new KindergartenContext(); context.Groups.Add(group); context.SaveChanges(); }); AddGroupCommand.NotifyCanExecute(true); Pipe.SetParameter("added_group_result", group); Finish(); }
private async void AddTarif(Tarif tarif) { if (!tarif.IsValid()) { return; } AddTarifCommand.NotifyCanExecute(false); await Task.Run(() => { var context = new KindergartenContext(); context.Tarifs.Add(tarif); context.SaveChanges(); }); AddTarifCommand.NotifyCanExecute(true); Pipe.SetParameter("tarif_result", tarif); Finish(); }
public void SetCredentials() { CredentialsForServer.Login = Login; CredentialsForServer.Password = Password; CredentialsForServer.DataSource = DataSource; CredentialsForServer.DataBase = DataBase; try { using (KindergartenContext db = new KindergartenContext()) { db.Database.Migrate(); if (db.Users.ToList().Count() == 0 && db.Employees.ToList().Count() == 0) { db.Employees.Add(new Employee { Name = "Администратор", Lastname = "Администратор" }); db.SaveChanges(); db.Users.Add(new User { Login = "******", Password = "******", LevelAccess = 1, EmployeeId = db.Employees.Local.First().Id }); db.SaveChanges(); } if (db.Menus.ToList().Count() == 0) { db.Menus.Add(new Menu { Name = "Меню 1" }); db.SaveChanges(); } MessageBox.Show("Подключение успешно создано!", "Успех", MessageBoxButton.OK, MessageBoxImage.Information); } } catch (Exception ex) { MessageBox.Show("Ошибка! " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
private async void Save() { if (CurrentGroup == SelectedGroup) { return; } SaveCommand.NotifyCanExecute(false); await Task.Run(() => { var context = new KindergartenContext(); var child = context.Children.First(c => c.Id == _currentChild.Id); child.GroupId = SelectedGroup.Id; context.SaveChanges(); }); SaveCommand.NotifyCanExecute(true); Pipe.SetParameter("saved_group_result", SelectedGroup); Finish(); }
private void AddExpense() { if (MoneyExpense <= 0) { return; } var expense = new Expense { ExpenseType = (ExpenseType)this["SelectedExpenseType"], Money = MoneyExpense, Description = DescriptionExpense }; var context = new KindergartenContext(); context.Expenses.Add(expense); context.SaveChanges(); App.Logger.Trace("New expense added"); Pipe.SetParameter("added_expense", expense); Finish(); }
public ApplicationsController(KindergartenContext context, IMapper mapper) { _context = context; _mapper = mapper; }
public Repository(KindergartenContext context) { _context = context; }
private async void AddChild(Child child) { if (!child.IsValid()) { MessageBox.Show("Не все поля заполнены/пункты выбраны", "Внимание", MessageBoxButton.OK, MessageBoxImage.Warning); return; } var now = DateTime.Now; if (ChildAdditionDate > now) { MessageBox.Show("Ввод будущей даты добавления запрещён", "Внимание", MessageBoxButton.OK, MessageBoxImage.Warning); return; } if (child.BirthDate > ChildAdditionDate) { MessageBox.Show("Дата рождения должна быть меньше даты добавления", "Внимание", MessageBoxButton.OK, MessageBoxImage.Warning); return; } if (SelectedOther == null && SelectedMother == null && SelectedFather == null) { MessageBox.Show("Должен быть выбран хотя бы один из родителей либо иной представитель", "Некорректный выбор", MessageBoxButton.OK, MessageBoxImage.Information); return; } if (BroughtParent == Parents.Father && SelectedFather == null || BroughtParent == Parents.Mother && SelectedMother == null || BroughtParent == Parents.Other && SelectedOther == null) { MessageBox.Show("Выберите существующего родителя"); return; } AddChildCommand.NotifyCanExecute(false); ParentChild broghtParent = null; EnterChild enterChild = null; bool needAddPayments = StartedToPayFromAdditionDate; await Task.Run(() => { string imageFileName = null; try { if (_imageUri != null) { var savePath = Path.Combine(Settings.AppFilePaths.ChildImages, CommonHelper.GetUniqueString()); imageFileName = ImageUtil.SaveImage(_imageUri, savePath); child.Person.PhotoPath = Path.GetFileName(imageFileName); } // groups and tarifs (in OnLoaded) are from other context child.GroupId = child.Group.Id; child.Group = null; child.TarifId = child.Tarif.Id; enterChild = new EnterChild { Child = child, EnterDate = ChildAdditionDate }; child.LastEnterChild = enterChild; var context = new KindergartenContext(); if (needAddPayments) { // to no debt range add if (now.Year != ChildAdditionDate.Year && now.Month != ChildAdditionDate.Month) { // 1) the first fictitious payment for start range context.MonthlyPayments.Add(new MonthlyPayment { ChildId = child.Id, PaymentDate = ChildAdditionDate, MoneyPaymentByTarif = 0, // 0 - because to make no debt }); } // 2) the second fictitious payment for end range context.MonthlyPayments.Add(new MonthlyPayment { ChildId = child.Id, PaymentDate = now, MoneyPaymentByTarif = child.Tarif.MonthlyPayment, DebtAfterPaying = InitialDebt, }); } child.Tarif = null; context.EnterChildren.Add(enterChild); if (SelectedFather != null) { var parentChild = new ParentChild { Child = child, ParentId = SelectedFather.Id, ParentType = Parents.Father }; context.ParentChildren.Add(parentChild); if (BroughtParent == Parents.Father) { broghtParent = parentChild; } } if (SelectedMother != null) { var parentChild = new ParentChild { Child = child, ParentId = SelectedMother.Id, ParentType = Parents.Mother }; context.ParentChildren.Add(parentChild); if (BroughtParent == Parents.Mother) { broghtParent = parentChild; } } if (SelectedOther != null) { var parentChild = new ParentChild { Child = child, ParentId = SelectedOther.Id, ParentType = Parents.Other, ParentTypeText = OtherParentText }; context.ParentChildren.Add(parentChild); if (BroughtParent == Parents.Other) { broghtParent = parentChild; } } context.SaveChanges(); App.Logger.Debug("Child added"); } catch { if (imageFileName != null) { File.Delete(imageFileName); } throw; } }); Pipe.SetParameter("saved_child_result", child); Pipe.SetParameter("brought_parent", broghtParent); Pipe.SetParameter("enter", enterChild); // ReSharper disable once RedundantExplicitArraySize var parents = new ParentChild[3] { new ParentChild { Parent = SelectedFather, ParentType = Parents.Father }, new ParentChild { Parent = SelectedMother, ParentType = Parents.Mother }, new ParentChild { Parent = SelectedOther, ParentType = Parents.Other } }; Pipe.SetParameter("parents", parents); AddChildCommand.NotifyCanExecute(true); Finish(); }
public SpecialRequirementsController(KindergartenContext context) { _context = context; }
public ApplicationService(KindergartenContext context) { this.kindergartenContext = context; }