Esempio n. 1
0
 public void Delete(Guid id)
 {
     using (var DB = new MainContext())
     {
         DB.Entry(GetProfessorById(id)).State = System.Data.Entity.EntityState.Deleted;
         DB.SaveChanges();
     }
 }
Esempio n. 2
0
 public bool Add(ProfessorModel data)
 {
     using (var DB = new MainContext())
     {
         DB.Professors.Add(data);
         DB.SaveChanges();
         return true;
     }
     return false;
 }
Esempio n. 3
0
 public bool Add(SpaceModel data)
 {
     using (var DB = new MainContext())
     {
         DB.Spaces.Add(data);
         DB.SaveChanges();
         return true;
     }
     return false;
 }
Esempio n. 4
0
 public bool Edit(ProfessorModel data)
 {
     using (var DB = new MainContext())
     {
         DB.Professors.Attach(data);
         DB.Entry(data).State = System.Data.Entity.EntityState.Modified;
         DB.SaveChanges();
         return true;
     }
     return false;
 }
Esempio n. 5
0
 public bool Add(SubjectModel model)
 {
     using (var DB = new MainContext())
     {
         DB.Subjects.Add(model);
         DB.Entry(model.Space).State = System.Data.Entity.EntityState.Unchanged;
         DB.SaveChanges();
         return true;
     }
     return false;
 }
Esempio n. 6
0
 public bool ChangeRating(Guid TestId, int Rating)
 {
     using (var DB = new MainContext())
     {
         var test = DB.Tests.Where(x => x.Id == TestId).FirstOrDefault();
         test.Rating += Rating;
         DB.Entry(test).State = System.Data.Entity.EntityState.Modified;
         DB.SaveChanges();
         return true;
     }
     return false;
 }
Esempio n. 7
0
 public bool Add(StatModel model)
 {
     using (var DB = new MainContext())
     {
         model.TestModel.Questions = null;
         DB.Stats.Add(model);
         DB.Entry(model.TestModel).State = System.Data.Entity.EntityState.Unchanged;
         DB.SaveChanges();
         return true;
     }
     return false;
 }
Esempio n. 8
0
        public bool Add(TestModel model)
        {
            model.Creator = new UserProfile()
            {
                UserId = WebMatrix.WebData.WebSecurity.CurrentUserId,
                UserName = WebMatrix.WebData.WebSecurity.CurrentUserName
            };
            using (var DB = new MainContext())
            {
                var context = new ValidationContext(model.Infos.First(), serviceProvider: null, items: null);
                var validationResults = new List<ValidationResult>();

                bool isValid = Validator.TryValidateObject(model.Infos.First(), context, validationResults, true);
                if (isValid)
                {
                    DB.Infos.Add(model.Infos.First());
                    DB.SaveChanges();
                }
                else
                    model.Infos.Remove(model.Infos.First());

                DB.Tests.Add(model);
                DB.Entry(model.Space).State = System.Data.Entity.EntityState.Unchanged;
                DB.Entry(model.Subject).State = System.Data.Entity.EntityState.Unchanged;
                DB.Entry(model.Creator).State = System.Data.Entity.EntityState.Unchanged;

                if (model.Infos != null)
                {
                    foreach (var infoModel in model.Infos)
                    {
                        DB.Entry(infoModel).State = System.Data.Entity.EntityState.Unchanged;
                    }
                }
                DB.SaveChanges();
                return true;
            }
            return false;
        }