public User AddUser(User user) { if (user.Login != "" && user.Password != "" && user.Role != "" && user.Name != "" && user.Surname != "") { using (db_schedule db = new db_schedule()) { var count = db.User .Where(s => s.Login == user.Login) .Count(); if (count == 0) { db.User.Add(user); db.SaveChanges(); return(user); } else { user.error = true; user.error_message = "Пользователь с таким логином уже существует!"; return(user); } } } else { user.error = true; user.error_message = "Заполнены не все данные!"; return(user); } }
public void TransactionDeleteOrder(int id) { using (db_schedule db = new db_schedule()) { using (var transaction = db.Database.BeginTransaction()) { try { Order order = db.Order .Where(o => o.ID_Order == id) .FirstOrDefault(); List <Shedule> shedules = db.Shedule .Where(o => o.Order_ID == order.ID_Order).ToList(); db.Shedule.RemoveRange(shedules); db.Order.Remove(order); db.SaveChanges(); transaction.Commit(); } catch { transaction.Rollback(); } } } }
//собственно алгоритм public void Create() { Building.PreBuild(); Building.Build(); for (int i = 0; i < Building.Classes.Count; i++) { for (int j = 0; j < Building.Orders.Count; j++) { Shedule sh = new Shedule(); sh.Couple_ID = Building.Classes[i].Couple; sh.DayOfWeek = Building.Classes[i].Day_Of_Week; sh.NumDem = Building.Classes[i].NumDel; sh.Order_ID = Building.Orders[j].ID_Order; sh.Room_ID = Building.Classes[i].Room; using (db_schedule db = new db_schedule()) { Shedule shedule = db.Shedule .Where(s => s.DayOfWeek == sh.DayOfWeek && s.Couple_ID == sh.Couple_ID && s.NumDem == sh.NumDem && s.Room_ID == sh.Room_ID) .FirstOrDefault(); if (shedule == null) { AddShedule(sh); } else { UpdateShedule(sh); } db.SaveChanges(); } //AddShedule(sh); } } }
//class Room public List <Room> SelectRoom() { using (db_schedule db = new db_schedule()) { List <Room> room = db.Room.ToList(); return(room); } }
//class Couple public List <Couple> SelectCouple() { using (db_schedule db = new db_schedule()) { List <Couple> couples = db.Couple.ToList(); return(couples); } }
//class Subject public List <Subject> SelectSubject() { using (db_schedule db = new db_schedule()) { List <Subject> subject = db.Subject.ToList(); return(subject); } }
//readonly string connectionString = @"Data Source = (LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\Наталья\Source\Repos\autoScheduling5\Service\SchedulingService\App_Data\db_schedule.mdf;Integrated Security = True"; //class User public List <User> SelectUser() { using (db_schedule db = new db_schedule()) { List <User> users = db.User.ToList(); return(users); } }
//class Group public List <Group> SelectGroup() { using (db_schedule db = new db_schedule()) { List <Group> groups = db.Group.ToList(); return(groups); } }
public Shedule AddShedule(Shedule shedule) { using (db_schedule db = new db_schedule()) { db.Shedule.Add(shedule); db.SaveChanges(); return(shedule); } }
public Subject FindByIDSubject(int id) { using (db_schedule db = new db_schedule()) { Subject subject = db.Subject .Where(o => o.ID_Subject == id) .FirstOrDefault(); return(subject); } }
public Group FindByIDGroup(int id) { using (db_schedule db = new db_schedule()) { Group group = db.Group .Where(o => o.ID_Group == id) .FirstOrDefault(); return(group); } }
public User FindByIDUser(int id) { using (db_schedule db = new db_schedule()) { User user = db.User .Where(o => o.ID_User == id) .FirstOrDefault(); return(user); } }
public Couple FindByIDCouple(int id) { using (db_schedule db = new db_schedule()) { Couple couple = db.Couple .Where(s => s.ID_Couple == id) .FirstOrDefault(); return(couple); } }
public Room FindByIDRoom(int id) { using (db_schedule db = new db_schedule()) { Room room = db.Room .Where(o => o.ID_Room == id) .FirstOrDefault(); return(room); } }
public void DeleteShedule(int id) { using (db_schedule db = new db_schedule()) { Shedule shedule = db.Shedule .Where(s => s.ID_Shedule == id) .FirstOrDefault(); db.Shedule.Remove(shedule); db.SaveChanges(); } }
public Shedule FindByIDShedule(int id) { using (db_schedule db = new db_schedule()) { Shedule shedule = db.Shedule .Where(s => s.ID_Shedule == id) .FirstOrDefault(); db.SaveChanges(); return(shedule); } }
public void DeleteGroup(int id) { using (db_schedule db = new db_schedule()) { Group group = db.Group .Where(o => o.ID_Group == id) .FirstOrDefault(); db.Group.Remove(group); db.SaveChanges(); } }
public void DeleteSubject(int id) { using (db_schedule db = new db_schedule()) { Subject subject = db.Subject .Where(o => o.ID_Subject == id) .FirstOrDefault(); db.Subject.Remove(subject); db.SaveChanges(); } }
public void DeleteUser(int id) { using (db_schedule db = new db_schedule()) { User user = db.User .Where(o => o.ID_User == id) .FirstOrDefault(); db.User.Remove(user); db.SaveChanges(); } }
public void DeleteRoom(int id) { using (db_schedule db = new db_schedule()) { Room room = db.Room .Where(o => o.ID_Room == id) .FirstOrDefault(); db.Room.Remove(room); db.SaveChanges(); } }
public void UpdateShedule(Shedule shedule) { using (db_schedule db = new db_schedule()) { Shedule sh = db.Shedule .Where(s => s.ID_Shedule == shedule.ID_Shedule) .FirstOrDefault(); sh.Order_ID = shedule.Order_ID; db.SaveChanges(); } }
public void UpdateSubject(Subject subject) { using (db_schedule db = new db_schedule()) { Subject s = db.Subject .Where(o => o.ID_Subject == subject.ID_Subject) .FirstOrDefault(); s.Name = subject.Name; db.SaveChanges(); } }
public void UpdateRoom(Room room) { using (db_schedule db = new db_schedule()) { Room s = db.Room .Where(o => o.ID_Room == room.ID_Room) .FirstOrDefault(); s.Number = room.Number; db.SaveChanges(); } }
public void UpdateGroup(Group group) { using (db_schedule db = new db_schedule()) { Group s = db.Group .Where(o => o.ID_Group == group.ID_Group) .FirstOrDefault(); s.Name = group.Name; db.SaveChanges(); } }
public void UpdateCouple(Couple couple) { if (couple.Start != null && couple.End != null) { using (db_schedule db = new db_schedule()) { Couple c = db.Couple .Where(s => s.ID_Couple == couple.ID_Couple) .FirstOrDefault(); c.Start = couple.Start; c.End = couple.End; } } }
public Subject AddSubject(Subject subject) { using (db_schedule db = new db_schedule()) { var count = db.Subject .Where(s => s.Name == subject.Name) .Count(); if (count == 0) { db.Subject.Add(subject); db.SaveChanges(); } } return(subject); }
public Group AddGroup(Group group) { using (db_schedule db = new db_schedule()) { var count = db.Group .Where(s => s.Name == group.Name) .Count(); if (count == 0) { db.Group.Add(group); db.SaveChanges(); } } return(group); }
public Room AddRoom(Room room) { using (db_schedule db = new db_schedule()) { var count = db.Room .Where(s => s.Number == room.Number) .Count(); if (count == 0) { db.Room.Add(room); db.SaveChanges(); } } return(room); }
public Couple AddCouple(Couple couple) { if (couple.Start != null && couple.End != null) { using (db_schedule db = new db_schedule()) { db.Couple.Add(couple); db.SaveChanges(); return(couple); } } else { return(couple); } }
public bool CheckLoginUser(string login) { using (db_schedule db = new db_schedule()) { User u = db.User .Where(s => s.Login == login) .FirstOrDefault(); if (u != null) { return(true); } else { return(false); } } }