コード例 #1
0
        private void DeleteSchoolTypeDetailed(int schoolTypeId, int userId)
        {
            try
            {
                using (JakieKieszonkoweEntities db = new JakieKieszonkoweEntities())
                {
                    var isAdmin = db.Users.FirstOrDefault(i => i.Id_user == userId).IsAdmin;
                    if (!isAdmin)
                    {
                        throw new Exception("Nie posiadasz wystarczających uprawnień.");
                    }
                    Education_stage educationStage = db.Education_stages.FirstOrDefault(i => i.Id_education_stage == schoolTypeId);

                    var children = db.Children.Where(i => i.Id_education_stage == schoolTypeId).Include(i => i.Child_pocket_money_option);
                    foreach (var child in children)
                    {
                        db.Children.Remove(child);
                    }

                    db.Education_stages.Remove(educationStage);
                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #2
0
 private void EditSchoolTypeDetailed(string schoolTypeName, int schoolTypeId, int userId)
 {
     try
     {
         using (JakieKieszonkoweEntities db = new JakieKieszonkoweEntities())
         {
             var isAdmin = db.Users.FirstOrDefault(i => i.Id_user == userId).IsAdmin;
             if (!isAdmin)
             {
                 throw new Exception("Nie posiadasz wystarczających uprawnień.");
             }
             Education_stage educationStage = db.Education_stages.FirstOrDefault(i => i.Id_education_stage == schoolTypeId);
             educationStage.Name = schoolTypeName;
             db.Education_stages.Attach(educationStage);
             db.Entry(educationStage).State = EntityState.Modified;
             db.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }