123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- using Microsoft.EntityFrameworkCore;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using WpfAppUI.Data;
- namespace WpfAppUI.Model
- {
- /// <summary>
- /// Класс реализует функционал запросов для бд
- /// </summary>
- public static class DBRequests
- {
- //Все рабочие
- public static ICollection<Emploee> AllDataRequest()
- {
- ApplicationContextUI db = new ApplicationContextUI();
- return db.Emploees.ToList();
- }
- //Рабочий по ID
- public static Emploee EmploeeById(int id)
- {
- using (ApplicationContextUI db = new ApplicationContextUI())
- {
- return db.Emploees.Where(i => i.id == id).FirstOrDefault();
- }
- }
- //Все должности
- public static ICollection<Post> PostRequest()
- {
- using (ApplicationContextUI db = new ApplicationContextUI())
- {
- return db.Posts.ToList();
- }
- }
- //Удалить сотрудника
- public static bool DeleteEmploeeById(int id)
- {
- using (ApplicationContextUI db = new ApplicationContextUI())
- {
- var emploee = db.Emploees.Where(i => i.id == id).FirstOrDefault();
- if (emploee != null)
- {
- db.Remove(emploee);
- db.SaveChanges();
- return true;
- }
- return false;
- }
- }
- //Изменить данные о сотруднике
- public static void ChangeEmploeeData(int id, string surname, string name, Post post, DateTime birthday, string phone, string mail, string patronymic = null)
- {
- ApplicationContextUI db = new ApplicationContextUI();
- var emploee = db.Emploees.Where(i => i.id == id).FirstOrDefault();
- emploee.Surname = surname;
- emploee.Name = name;
- emploee.Post = post;
- emploee.Birthday = birthday;
- emploee.Phone = phone;
- emploee.Mail = mail;
- emploee.Patronymic = patronymic;
- db.SaveChanges();
- db.Dispose();
- }
- //Новый сотрудник
- public static bool AddNewEmploee(string surname, string name, Post post, DateTime birthday, string phone, string mail, string patronymic = null)
- {
- ApplicationContextUI db = new ApplicationContextUI();
- bool chek = false;
- if (!db.Emploees.Any(el => el.Name == name && el.Surname == surname && el.Mail == mail || el.Birthday == birthday))
- {
- Emploee emploee = new Emploee
- {
- Surname = surname,
- Name = name,
- Mail = mail,
- Birthday = birthday,
- Phone = phone,
- Post = post,
- Patronymic = patronymic,
- };
- db.Emploees.Add(emploee);
- db.SaveChanges();
- db.Dispose();
- chek = true;
- }
- return chek;
- }
- }
- }
|