private Prepod CopyPrepod(Prepod dbPrepod, Prepod importPrepod, Department department) { dbPrepod.Departments.Add(department); // повторно встречается - совместитель if (dbPrepod.Present) { dbPrepod.DepartmentsString = dbPrepod.DepartmentsString + ", " + importPrepod.DepartmentsString; } else { dbPrepod.Present = true; dbPrepod.ImportId = importPrepod.ImportId; dbPrepod.Degree = importPrepod.Degree; dbPrepod.DepartmentsString = importPrepod.DepartmentsString; dbPrepod.Name = importPrepod.Name; dbPrepod.Patronymic = importPrepod.Patronymic; dbPrepod.Position = importPrepod.Position; dbPrepod.Rank = importPrepod.Rank; dbPrepod.Surename = importPrepod.Surename; // ДОПОЛНЕНИИ ИНФОРМАЦИИ ОБ импортируемых ПРЕПОДАВАТЕЛЯХ СОБСТВЕННЫМИ ДАННЫМИ - не перезаписывать (тлф, , почта, ...) // dbPrepod.Birthday // dbPrepod.Email; // dbPrepod.Phone; } return(dbPrepod); }
private static void PrepodsInit(AspiranturaContext context) { // var positions = new Position[] // { // new Position {Id = 1, Abbreviation = "декан", Name="декан факультету"}, // new Position {Id = 2, Abbreviation = "заст.декана", Name="заступник декана факультету"}, // new Position {Id = 3, Abbreviation = "зав.кафедри", Name="завідувач кафедрою"}, // new Position {Id = 4, Abbreviation = "заст.зав.кафедри", Name="заступник завідувача кафедрою"}, // new Position {Id = 5, Abbreviation = "ст.викладач", Name="старший викладач"}, // new Position {Id = 6, Abbreviation = "викладач", Name="викладач"}, // new Position {Id = 7, Abbreviation = "інше", Name="інше"}, // }; // foreach (Position item in positions) { // context.Positions.Add (item); // } // context.SaveChanges (); var prepods = new Prepod[] { new Prepod { Surename = "Гуру", Name = "Василь", Patronymic = "Петрович", Phone = "2903311", Email = "*****@*****.**", Present = true, Position = Position.ст_викладач, Rank = Rank.професор, Degree = Degree.доктор_наук }, new Prepod { Surename = "Вершина", Name = "Сергій", Patronymic = "Михайлович", Phone = "12203311", Email = "*****@*****.**", Present = true, Position = Position.зав_каф }, }; foreach (Prepod item in prepods) { context.Prepods.Add(item); } context.SaveChanges(); }
public async Task <IActionResult> Put([FromRoute] int id, [FromBody] Prepod prepod) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } prepod.DepartmentsString = GetDepartmentsString(prepod); // // заполнение поля акронимами кафедр // prepod.DepartmentsString = String.Empty; // foreach (var item in prepod.Departments.OrderBy (o => o.Acronym)) { // var dep = _context.Departments.FirstOrDefault (i => i.Id == item.Id); // if (String.IsNullOrEmpty (prepod.DepartmentsString)) // prepod.DepartmentsString = dep?.Acronym; // else // prepod.DepartmentsString = prepod.DepartmentsString + ", " + dep?.Acronym; // } _context.Entry(prepod).State = EntityState.Modified; try { await EditAssignedDepartments(prepod); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { // if (!DepartmentExists (id)) { // return NotFound (); // } else { // throw; // } } return(NoContent()); }
public async Task <PrepodSelectLists> GetListsAsync([FromRoute] int id) { Prepod prepod = await _context.Prepods.FirstOrDefaultAsync(m => m.Id == id); PrepodSelectLists prepodSelectLists = new PrepodSelectLists(prepod); return(prepodSelectLists); }
public ActionResult DeleteConfirmed(int id) { Prepod prepod = db.Prepods.Find(id); db.Prepods.Remove(prepod); db.SaveChanges(); return(RedirectToAction("Index")); }
private Aspirant InitAspirantFromAspirantImport(AspirantImport aspirantImport) { DateTime birthday = DateTime.FromOADate(aspirantImport.Birthday); Aspirant aspirant = _context.Aspirants.FirstOrDefault(a => (a.Name == aspirantImport.Name && a.Surename == aspirantImport.Surename && a.Patronymic == aspirantImport.Patronymic && a.Birthday.Value.Date == birthday.Date)); // Возвращаем null, если аспирант уже есть в БД if (aspirant != null) { return(null); } aspirant = new Aspirant(); aspirant.Name = aspirantImport.Name; aspirant.Surename = aspirantImport.Surename; aspirant.Patronymic = aspirantImport.Patronymic; aspirant.Birthday = birthday; aspirant.Phone = aspirantImport.Phone; aspirant.Email = aspirantImport.Email; aspirant.Doctorant = false; aspirant.Present = true; aspirant.StatusType = StatusType.новий; aspirant.Sex = aspirantImport.Sex.Contains("чоловік") ? true : false; aspirant.Budget = aspirantImport.Budget.Contains("держзамовлення") ? true : false; // Enum из строки aspirant.StudyForm = (StudyForm)Enum.Parse(typeof(StudyForm), aspirantImport.StudyForm); string acronym = aspirantImport.Department.Split(new char[] { ';' }) [0].Trim(); var dep = _context.Departments.FirstOrDefault(d => d.Acronym.Contains(acronym)); aspirant.DepartmentId = _context.Departments.FirstOrDefault(d => d.Acronym == acronym).Id; string specialityId = aspirantImport.Speciality.Split(new char[] { ';' }) [0].Trim(); aspirant.SpecialityId = Int32.Parse(specialityId); Prepod prepod = _context.Prepods.FirstOrDefault(p => (p.DepartmentsString.ContainsWholeWord(acronym) && p.Surename == aspirantImport.Supervisor)); if (prepod != null) { aspirant.PrepodId = prepod.Id; } else { aspirant.PrepodId = 0; } return(aspirant); }
public ActionResult Edit([Bind(Include = "PrepodID,Name,Dolznost,Vozrast,KafedraID")] Prepod prepod) { if (ModelState.IsValid) { db.Entry(prepod).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.KafedraID = new SelectList(db.Kafedras, "KafedraID", "Name", prepod.KafedraID); return(View(prepod)); }
public PrepodSelectLists(Prepod prepod) { Positions = Helper.GetPositions(); Ranks = Helper.GetRanks(); Degrees = Helper.GetDegrees(); if (prepod != null) { selectedRank = Ranks.FirstOrDefault(k => k.Value == (int)prepod.Rank); selectedDegree = Degrees.FirstOrDefault(k => k.Value == (int)prepod.Degree); selectedPosition = Positions.FirstOrDefault(k => k.Value == (int)prepod.Position); } }
public ActionResult Create([Bind(Include = "PrepodID,Name,Dolznost,Vozrast,KafedraID")] Prepod prepod) { if (ModelState.IsValid) { db.Prepods.Add(prepod); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.KafedraID = new SelectList(db.Kafedras, "KafedraID", "Name", prepod.KafedraID); return(View(prepod)); }
public async Task <IActionResult> FormularImport([FromBody] IEnumerable <Prepod> importPrepods) { if (!ModelState.IsValid) { return(BadRequest("Перевірте наявність даних в полях Surename та Name в усіх строках, починаючи з другої.")); } List <Prepod> dbPrepods = _context.Prepods.ToList(); foreach (var dbPrepod in dbPrepods) { // сначала делаем всех неактивніми, а затем по IDImport - активными и вносим изменения dbPrepod.Present = false; dbPrepod.Departments = new List <Department> (); } foreach (var importPrepod in importPrepods) { // Распарсить полный путь до акронима Department department = _context.Departments.FirstOrDefault(d => d.Acronym == importPrepod.DepartmentsString); if (department == null) { return(BadRequest("Перевірте Кафедру для " + importPrepod.Surename)); } Prepod dbPrepod = dbPrepods.FirstOrDefault(p => p.ImportId == importPrepod.ImportId); if (dbPrepod == null) { dbPrepod = CopyPrepod(new Prepod() { Departments = new List <Department> () }, importPrepod, department); // dbPrepod.Departments = new List<Department> (); dbPrepods.Add(dbPrepod); _context.Prepods.Add(dbPrepod); await _context.SaveChangesAsync(); } else { dbPrepod = CopyPrepod(dbPrepod, importPrepod, department); } } foreach (var dbPrepod in dbPrepods) { await EditAssignedDepartments(dbPrepod); } await _context.SaveChangesAsync(); return(Ok()); }
static Prepod Getprepod() { Console.WriteLine("Добавляем препода:"); var st = new Prepod(); Console.WriteLine("Name:"); st.Name = Console.ReadLine(); Console.WriteLine("FirstName:"); st.FirstName = Console.ReadLine(); Console.WriteLine("MainCource:"); st.MainCource = Console.ReadLine(); return(st); }
// GET: Prepods/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Prepod prepod = db.Prepods.Find(id); if (prepod == null) { return(HttpNotFound()); } return(View(prepod)); }
public async Task <IActionResult> Post([FromBody] Prepod prepod) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } prepod.DepartmentsString = GetDepartmentsString(prepod); _context.Prepods.Add(prepod); await _context.SaveChangesAsync(); await EditAssignedDepartments(prepod); return(Ok(prepod.Id)); }
private bool IsPrepodUniqByName(Prepod prepod) { bool uniq = false; if (String.IsNullOrEmpty(prepod.Patronymic)) { uniq = !_context.Prepods.Any(p => p.Surename + p.Name == prepod.Surename + prepod.Name); } else { uniq = !_context.Prepods.Any(p => p.Surename + p.Name + p.Patronymic == prepod.Surename + prepod.Name + prepod.Patronymic); } return(uniq); }
// GET: Prepods/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Prepod prepod = db.Prepods.Find(id); if (prepod == null) { return(HttpNotFound()); } ViewBag.KafedraID = new SelectList(db.Kafedras, "KafedraID", "Name", prepod.KafedraID); return(View(prepod)); }
static void Main(string[] args) { Console.WriteLine(ushort.MaxValue); string str = "Юля_123_Чистякова"; string sub_str = "123"; int index = str.IndexOf(sub_str); if (index == -1) { Console.WriteLine("Подстроки нет в строке"); } else { Console.WriteLine("Подстрока содержится в строке"); } double[,] arr = new double[2, 2]; Random rand = new Random(); for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { arr[i, j] = rand.Next(1, 99); Console.Write(arr[i, j] + " "); } } Date d1 = new Date(); Date d2 = new Date(); d1.day = 1; d1.month = 7; d2.day = 8; d2.month = 6; Console.WriteLine("\nd1 эквивалентно d2? - " + d1.Equals(d2)); Student st = new Student(); Prepod pr = new Prepod(); st.minus(); st.plus(); pr.plus(); Console.ReadLine(); }
// заполнение поля акронимами кафедр private string GetDepartmentsString(Prepod prepod) { string departmentsString = String.Empty; foreach (var item in prepod.Departments.OrderBy(o => o.Acronym)) { var dep = _context.Departments.FirstOrDefault(i => i.Id == item.Id); if (String.IsNullOrEmpty(departmentsString)) { departmentsString = dep?.Acronym; } else { departmentsString = departmentsString + ", " + dep?.Acronym; } } return(departmentsString); }
static void Main(string[] args) { double min = double.MinValue; Console.WriteLine(min); string a = Console.ReadLine(); string b = Console.ReadLine(); string c = a + b; Console.WriteLine(c); int[][] mass = new int[2][]; mass[0] = new int[3] { 1, 2, 3 }; mass[1] = new int[5] { 1, 2, 3, 4, 5 }; foreach (int[] i in mass) { foreach (int number in i) { Console.Write($"{number} \t"); } Console.WriteLine(); } Time c1 = new Time { Minutes = 23, Seconds = 12 }; Time c2 = new Time { Minutes = 12, Seconds = 12 }; bool result = c1 < c2; bool result1 = c1 == c2; bool result2 = c1 > c2; Console.WriteLine(result); Console.WriteLine(result1); Student student = new Prepod(); Console.ReadKey(); }
// изменить список кафедр (мест работы) private async Task EditAssignedDepartments(Prepod prepod) { // пересечение двух множеств по Id var workPlaces = prepod.Departments.ToList(); var prepodDepartments = _context.PrepodsDepartments.Where(i => i.PrepodId == prepod.Id).ToList(); // выбрать в PrepodDepartments записи, которые отсутствуют в workPlaces (prepod.Departments) - для удаления var forDelete = (from d in prepodDepartments where (!workPlaces.Any(x => x.Id == d.DepartmentId)) select d).ToList(); // выбрать в workPlaces записи, которые отсутствуют в PrepodDepartments - для добавления var forAdd = (from d in workPlaces where (!prepodDepartments.Any(x => x.DepartmentId == d.Id))select(new PrepodDepartment { PrepodId = prepod.Id, DepartmentId = d.Id })).ToList(); _context.PrepodsDepartments.RemoveRange(forDelete); _context.PrepodsDepartments.AddRange(forAdd); await _context.SaveChangesAsync(); }
private bool IsPrepodUniq(Prepod prepod, List <Prepod> dbPrepods) { return(!dbPrepods.Any(p => p.ImportId == prepod.ImportId)); }
public async Task AddPrepodAsync(Prepod prepod) { await _context.Prepods.AddAsync(prepod); await _context.SaveChangesAsync(); }
public Task DeletePrepodAsync(Prepod prepod) { _context.Prepods.Remove(prepod); return(_context.SaveChangesAsync()); }
public Task EditPrepodAsync(Prepod prepod) { _context.Prepods.Update(prepod); return(_context.SaveChangesAsync()); }