/// <summary> /// Редактировать/Добавить тему /// </summary> /// <param name="newTheme">Новая тема</param> /// <returns></returns> public static object EditORAddTheme(Theme newTheme = null) { object res = null; if (newTheme != null) { try { using (var context = new TrainSQL_Entities()) { if (IsThemeExists(newTheme.ThemeID)) { context.Themes.FirstOrDefault(x => x.ThemeID == newTheme.ThemeID).ThemeName = newTheme.ThemeName; context.Themes.FirstOrDefault(x => x.ThemeID == newTheme.ThemeID).Theory = newTheme.Theory; } else { context.Themes.Add(newTheme); } context.SaveChanges(); } } catch (Exception ex) { res = ex; MessageBox.Show(ex.ToString()); } } return(res); }
/// <summary> /// Удалить тему /// </summary> /// <param name="theme">Тема</param> /// <returns></returns> public static object DeleteTheme(Theme theme = null) { object result = null; if (theme != null) { try { using (var context = new TrainSQL_Entities()) { var delTheme = context.Themes.FirstOrDefault(x => x.ThemeID == theme.ThemeID); if (delTheme != null) { context.Themes.Remove(delTheme); } context.SaveChanges(); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); result = ex; } } return(result); }
/// <summary> /// Удалить жалобу /// </summary> /// <param name="complaint">Жалоба</param> /// <returns></returns> public static object DeleteComplaint(Complaint complaint = null) { object res = null; if (complaint != null) { try { using (var context = new TrainSQL_Entities()) { var item = context.Complaints.FirstOrDefault(x => x.ComplaintID == complaint.ComplaintID); if (item != null) { context.Complaints.Remove(item); context.SaveChanges(); } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } return(res); }
/// <summary> /// Добавить прогресс пользователю /// </summary> /// <param name="login">Логин</param> /// <param name="rigthAnswers">Кол-во верно решённых заданий</param> /// <param name="totalQuestions">Общее число заданий в тесте</param> /// <returns></returns> public static object AddUserProgress(string login = "", int rigthAnswers = 0, int totalQuestions = 0) { object res = null; if (login != "") { try { using (var context = new TrainSQL_Entities()) { Progress progress = new Progress() { Login = login, TestDate = DateTime.Now, RightAnswersQuantity = rigthAnswers, TotalQuastionsQuantity = totalQuestions }; context.Progresses.Add(progress); context.SaveChanges(); } } catch (Exception ex) { res = ex; } } return(res); }
/// <summary> /// Удалить задание /// </summary> /// <param name="task">Задание</param> /// <returns></returns> public static object DeleteTask(TrainSQL_DAL.Task task = null) { object result = null; if (task != null) { try { using (var context = new TrainSQL_Entities()) { var delTask = context.Tasks.FirstOrDefault(x => x.TaskID == task.TaskID); if (delTask != null) { context.Tasks.Remove(delTask); } context.SaveChanges(); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); result = ex; } } return(result); }
public static object ChangeUserProperty(User user = null, string columnName = "", string newProperty = "") { if (user != null) { using (var context = new TrainSQL_Entities()) { try { switch (columnName) { case nameof(user.Login): context.Users.FirstOrDefault(x => x.Login == user.Login).Login = newProperty; break; case nameof(user.Password): context.Users.FirstOrDefault(x => x.Login == user.Login).Password = newProperty; break; case nameof(user.RoleID): context.Users.FirstOrDefault(x => x.Login == user.Login).RoleID = Convert.ToInt32(newProperty); break; default: return(new Exception()); break; } context.SaveChanges(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); return(ex); } } return(null); } return(new ArgumentNullException()); }
/// <summary> /// Отправить жалобу /// </summary> /// <param name="complaint">Жалоба</param> /// <returns></returns> public static object SendComplaint(Complaint complaint = null) { if (complaint != null) { try { using (var context = new TrainSQL_Entities()) { complaint.ComplaintID = context.Complaints.ToList().Last().ComplaintID + 1; context.Complaints.Add(complaint); context.SaveChanges(); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); return(ex); } } return(null); }
/// <summary> /// Редактировать/Добавить задание /// </summary> /// <param name="newTask">Задание</param> /// <returns></returns> public static object EditORAddTask(TrainSQL_DAL.Task newTask = null) { object res = null; if (newTask != null) { try { using (var context = new TrainSQL_Entities()) { if (IsTaskExists(newTask.TaskID)) { context.Tasks.FirstOrDefault(x => x.TaskID == newTask.TaskID).TaskText = newTask.TaskText; context.Tasks.FirstOrDefault(x => x.TaskID == newTask.TaskID).RightAnswer = newTask.RightAnswer; context.Tasks.FirstOrDefault(x => x.TaskID == newTask.TaskID).dbID = newTask.dbID; } else { context.Tasks.Add(new TrainSQL_DAL.Task() { TaskText = newTask.TaskText, RightAnswer = newTask.RightAnswer, dbID = newTask.dbID }); } context.SaveChanges(); } } catch (Exception ex) { res = ex; MessageBox.Show(ex.ToString()); } } return(res); }
/// <summary> /// Добавление польхователя /// </summary> /// <param name="newUser">Новый пользователь</param> /// <returns></returns> public static object AddUser(User newUser = null) { if (newUser != null) { using (var context = new TrainSQL_Entities()) { try { context.Users.Add(newUser); AddUserProgress(newUser.Login, 0, 5); context.SaveChanges(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); return(ex); } } return(null); } return(new ArgumentNullException()); }