예제 #1
0
 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);
     }
 }
예제 #2
0
        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();
                    }
                }
            }
        }
예제 #3
0
 //собственно алгоритм
 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);
         }
     }
 }
예제 #4
0
 //class Room
 public List <Room> SelectRoom()
 {
     using (db_schedule db = new db_schedule())
     {
         List <Room> room = db.Room.ToList();
         return(room);
     }
 }
예제 #5
0
 //class Couple
 public List <Couple> SelectCouple()
 {
     using (db_schedule db = new db_schedule())
     {
         List <Couple> couples = db.Couple.ToList();
         return(couples);
     }
 }
예제 #6
0
 //class Subject
 public List <Subject> SelectSubject()
 {
     using (db_schedule db = new db_schedule())
     {
         List <Subject> subject = db.Subject.ToList();
         return(subject);
     }
 }
예제 #7
0
        //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);
            }
        }
예제 #8
0
 //class Group
 public List <Group> SelectGroup()
 {
     using (db_schedule db = new db_schedule())
     {
         List <Group> groups = db.Group.ToList();
         return(groups);
     }
 }
예제 #9
0
 public Shedule AddShedule(Shedule shedule)
 {
     using (db_schedule db = new db_schedule())
     {
         db.Shedule.Add(shedule);
         db.SaveChanges();
         return(shedule);
     }
 }
예제 #10
0
 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);
     }
 }
예제 #11
0
 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);
     }
 }
예제 #12
0
 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);
     }
 }
예제 #13
0
 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);
     }
 }
예제 #14
0
 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);
     }
 }
예제 #15
0
 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();
     }
 }
예제 #16
0
 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);
     }
 }
예제 #17
0
 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();
     }
 }
예제 #18
0
 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();
     }
 }
예제 #19
0
 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();
     }
 }
예제 #20
0
 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();
     }
 }
예제 #21
0
 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();
     }
 }
예제 #22
0
        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();
            }
        }
예제 #23
0
        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();
            }
        }
예제 #24
0
        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();
            }
        }
예제 #25
0
 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;
         }
     }
 }
예제 #26
0
 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);
 }
예제 #27
0
 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);
 }
예제 #28
0
 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);
 }
예제 #29
0
 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);
     }
 }
예제 #30
0
 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);
         }
     }
 }