Esempio n. 1
0
        public ActionResult Create([Bind(Include = "Pass,Name,LastName,SurName,JoinDate,BirthDate,Status,OutDate,GroupId")] Aspirant aspirant)
        {
            if (ModelState.IsValid)        //если все заполнено верно
            {
                db.Aspirant.Add(aspirant); //добавляем аспиранта

                db.SaveChanges();
                return(RedirectToAction("Index", new { id = aspirant.GroupId }));//уходим на страницу его группы
            }

            ViewBag.GroupId = aspirant.GroupId;    //если не все заполнено,
            ViewBag.Group   = aspirant.Group.Name; //то восстанавливаем значения
            return(View(aspirant));                //и открываем страницу создания еще раз
        }
Esempio n. 2
0
        public ActionResult Details(int?id) //показываем аспиранта по id
        {
            if (id == null)                 //проверяем на валидность id
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Aspirant aspirant = db.Aspirant.Find(id);//проверяем существование такого аспиранта

            if (aspirant == null)
            {
                return(HttpNotFound());
            }
            return(View(aspirant));
        }
Esempio n. 3
0
        public ActionResult Edit(int?id) //редактируем аспиранта с id
        {
            if (id == null)              //проверяем id на валидность
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Aspirant aspirant = db.Aspirant.Find(id); //проверяем id на существование

            if (aspirant == null)
            {
                return(HttpNotFound());
            }
            ViewBag.GroupId = new SelectList(db.Group, "Id", "Name", aspirant.GroupId); //передаем варианты
                                                                                        //выбора группы
            return(View(aspirant));                                                     //открываем представление редактирования
        }
Esempio n. 4
0
        // изменить курс и статус аспиранта
        private async Task UpdateAspirantStatus(Order order)
        {
            foreach (var assignedAspirant in order.Aspirants.Where(aa => aa.Assigned))
            {
                Aspirant aspirant = _context.Aspirants.First(a => a.Id == assignedAspirant.Id);
                if (aspirant != null)
                {
                    aspirant.Course++;
                    switch (order.OrderType.Id)
                    {
                    case (int)OrderTypeEnum.Зарахування:
                        aspirant.Course = 1;
                        //                            aspirant.StatustypeId = assignedAspirant.
                        break;
                    }
                }

                AspirantOrder aspirantOrder = await _context.AspirantOrders.FirstOrDefaultAsync(a => (a.AspirantId == assignedAspirant.Id && a.OrderId == order.Id));

                if (assignedAspirant.Assigned)
                {
                    if (aspirantOrder != null)
                    {
                        aspirantOrder.AspirantId = assignedAspirant.Id;
                        aspirantOrder.OrderId    = order.Id;
                        _context.AspirantOrders.Update(aspirantOrder);
                    }
                    else
                    {
                        aspirantOrder = new AspirantOrder {
                            AspirantId = assignedAspirant.Id, OrderId = order.Id
                        };
                        _context.AspirantOrders.Add(aspirantOrder);
                    }
                }
                else
                {
                    if (aspirantOrder != null)
                    {
                        _context.AspirantOrders.Remove(aspirantOrder);
                    }
                }
            }
            await _context.SaveChangesAsync();
        }
Esempio n. 5
0
        public ActionResult Delete(int?id) //удаляем аспиранта с id
        {
            if (id == null)                //проверяем id на валидность
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Aspirant aspirant = db.Aspirant.Find(id); //и на существование

            if (aspirant == null)
            {
                return(HttpNotFound());
            }
            ObjectParameter output = new ObjectParameter("result", typeof(string));

            db.JoinNames("Aspirant", id, output);
            ViewBag.Name = (string)output.Value;
            return(View(aspirant)); //если все хорошо, открываем страницу подтверждения
        }
Esempio n. 6
0
        public ActionResult News()
        {
            string leader = Request.Form["Name"];

            if (leader == "Добавить")
            {
                return(Create(int.Parse(Request.Form["AspiId"])));
            }
            var i = (int?)Int32.Parse(leader.Substring(leader.IndexOf('№') + 1).TrimEnd(')')); //Собираем число после знака номера
                                                                                               //и без последней закр. скобки
            Leader   lead     = db.Leader.Find(i);
            Aspirant aspirant = db.Aspirant.Find(int.Parse(Request.Form["AspiId"]));           //добавляем руководителя

            lead.Aspirant.Add(aspirant);                                                       //аспиранту и наоборот
            db.Entry(lead).State     = EntityState.Modified;                                   //выставляем состояния в БД
            db.Entry(aspirant).State = EntityState.Modified;
            db.SaveChanges();                                                                  //сохраняем изменения
            return(RedirectToAction("Details", "Aspirants", new { id = aspirant.Pass }));      //И к конкретному аспиранту
        }
Esempio n. 7
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Surname,BirthDay,GroupId")] Aspirant aspirant)
        {
            if (id != aspirant.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                DateTime time_now = DateTime.Now;
                DateTime d1       = new DateTime(2020, 1, 20, 6, 20, 40);
                DateTime d2       = aspirant.BirthDay.Value;
                if (DateTime.Compare(time_now, d2) <= 0)
                {
                    ModelState.AddModelError("BirthDay", "BirthDay Error");
                    ViewData["GroupId"] = new SelectList(_context.Group, "Id", "GroupName", aspirant.GroupId);
                    return(View(aspirant));
                }



                try
                {
                    _context.Update(aspirant);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AspirantExists(aspirant.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["GroupId"] = new SelectList(_context.Group, "Id", "GroupName", aspirant.GroupId);
            return(View(aspirant));
        }
        public async Task <IActionResult> Create(int groupID, [Bind("Id,Name,Surname,BirthDay")] Aspirant aspirant)
        {
            //  if (ModelState.ContainsKey("{Name}"))
            //    ModelState["{Name}"].Errors.Clear();

            //  DateTime time_now = DateTime.Now;
            //  DateTime d2 = aspirant.BirthDay.Value;
            //  if (DateTime.Compare(time_now, d2) <= 0) { ModelState.AddModelError("BirthDay", "BirthDay Error"); return View(aspirant); }



            aspirant.GroupId = groupID;
            if (ModelState.IsValid)
            {
                var elements = _context.Aspirant.ToArray();
                foreach (var c in elements)
                {
                    //if ((aspirant.Name == c.Name) && (aspirant.Surname == c.Surname) && (aspirant.BirthDay == c.BirthDay) )
                    if ((aspirant.Name == c.Name) && (aspirant.Surname == c.Surname))
                    {
                        ViewData["GroupId"] = groupID;
                        ModelState.AddModelError("Name", "Coppy Error");
                        return(View(aspirant));
                    }
                }


                //  if (_context.Aspirant.Where(c => (c.Name == aspirant.Name)&&(c.Surname == aspirant.Surname)).Count() != 0 )
                // {
                //     ModelState.AddModelError("Name", "Coppy Error");
                //     return View(aspirant);
                //  }
                _context.Add(aspirant);
                await _context.SaveChangesAsync();

                // return RedirectToAction(nameof(Index));
                return(RedirectToAction("Index", "Aspirants", new { id = groupID, name = _context.Group.Where(c => c.Id == groupID).FirstOrDefault().GroupName }));
            }
            //ViewData["GroupId"] = new SelectList(_context.Group, "Id", "GroupName", aspirant.GroupId);
            // return RedirectToAction("Index", "Aspirants", new { id = groupID, name = _context.Group.Where(c => c.Id == groupID).FirstOrDefault().GroupName });
            return(View(aspirant));
        }
Esempio n. 9
0
 public Aspirant GetAspirant(Aspirant aspirant)
 {
     if (!string.IsNullOrWhiteSpace(ForeignLanguage))
     {
         aspirant.ForeignLanguage = ForeignLanguage;
     }
     if (!string.IsNullOrWhiteSpace(EnducationForm))
     {
         aspirant.EnducationForm = EnducationForm;
     }
     if (!string.IsNullOrWhiteSpace(EnducationDirection))
     {
         aspirant.EnducationDirection = EnducationDirection;
     }
     if (!string.IsNullOrWhiteSpace(Specialty))
     {
         aspirant.Specialty = Specialty;
     }
     if (!string.IsNullOrWhiteSpace(Cathedra))
     {
         aspirant.Cathedra = Cathedra;
     }
     if (!string.IsNullOrWhiteSpace(Faculty))
     {
         aspirant.Faculty = Faculty;
     }
     if (!string.IsNullOrWhiteSpace(Decree))
     {
         aspirant.Decree = Decree;
     }
     if (!string.IsNullOrWhiteSpace(DissertationTheme))
     {
         aspirant.DissertationTheme = DissertationTheme;
     }
     if (TeacherId.HasValue)
     {
         aspirant.TeacherId = TeacherId.Value;
     }
     return(aspirant);
 }
        public async Task <IActionResult> Edit(int id, int groupID, [Bind("Id,Name,Surname,BirthDay")] Aspirant aspirant)
        {
            //   DateTime time_now = DateTime.Now;
            // DateTime d1 = new DateTime(2020, 1, 20, 6, 20, 40);
            //  DateTime d2 = aspirant.BirthDay.Value;
            //  if (DateTime.Compare(time_now, d2) <= 0) { ModelState.AddModelError("BirthDay", "BirthDay Error"); return View(aspirant); }

            aspirant.GroupId = groupID;
            if (id != aspirant.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(aspirant);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AspirantExists(aspirant.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index", "Aspirants", new { id = groupID, name = _context.Group.Where(c => c.Id == groupID).FirstOrDefault().GroupName }));
                //  return RedirectToAction(nameof(Index));
            }
            return(RedirectToAction("Index", "Aspirants", new { id = groupID, name = _context.Group.Where(c => c.Id == groupID).FirstOrDefault().GroupName }));
            // ViewData["GroupId"] = new SelectList(_context.Group, "Id", "GroupName", aspirant.GroupId);
            // return View(aspirant);
        }
Esempio n. 11
0
        public async Task <IActionResult> Import(IFormFile fileExcel)
        {
            if (ModelState.IsValid)
            {
                if (fileExcel != null)
                {
                    using (var stream = new FileStream(fileExcel.FileName, FileMode.Create))
                    {
                        await fileExcel.CopyToAsync(stream);

                        using (XLWorkbook workBook = new XLWorkbook(stream, XLEventTracking.Disabled))
                        {
                            //перегляд усіх листів (в даному випадку категорій)
                            foreach (IXLWorksheet worksheet in workBook.Worksheets)
                            {
                                //worksheet.Name - назва категорії. Пробуємо знайти в БД, якщо відсутня, то створюємо нову
                                Group newgrp;
                                var   c = (from grp in _context.Group
                                           where grp.GroupName.Contains(worksheet.Name)
                                           select grp).ToList();
                                if (c.Count > 0)
                                {
                                    newgrp = c[0];
                                }
                                else
                                {
                                    newgrp           = new Group();
                                    newgrp.GroupName = worksheet.Name;
                                    // newgrp.Info = "from EXCEL";
                                    //додати в контекст
                                    _context.Group.Add(newgrp);
                                }
                                //перегляд усіх рядків
                                foreach (IXLRow row in worksheet.RowsUsed().Skip(1))
                                {
                                    try
                                    {
                                        Aspirant aspirant = new Aspirant();
                                        aspirant.Name     = row.Cell(1).Value.ToString();
                                        aspirant.Surname  = row.Cell(2).Value.ToString();
                                        aspirant.BirthDay = (DateTime)row.Cell(3).Value;
                                        // book.Info = row.Cell(6).Value.ToString();
                                        aspirant.Group   = newgrp;
                                        aspirant.GroupId = newgrp.Id;
                                        bool flag      = true;
                                        var  aspirants = _context.Aspirant.Where(n => n.GroupId == newgrp.Id).ToArray();
                                        foreach (var asp in aspirants)
                                        {
                                            if ((asp.Name == aspirant.Name) && (asp.Surname == aspirant.Surname) && (asp.BirthDay == aspirant.BirthDay))
                                            {
                                                flag = false; break;
                                            }
                                        }
                                        if (flag)
                                        {
                                            _context.Aspirant.Add(aspirant);
                                            await _context.SaveChangesAsync();
                                        }
                                    }
                                    catch (Exception e)
                                    {
                                        //logging самостійно :)
                                    }
                                }
                            }
                        }
                    }
                }

                await _context.SaveChangesAsync();
            }
            return(RedirectToAction(nameof(Index)));
        }
Esempio n. 12
0
        public async Task <IActionResult> Import(IFormFile fileExcel)
        {
            if (ModelState.IsValid)
            {
                if (fileExcel != null)
                {
                    using (var stream = new FileStream(fileExcel.FileName, FileMode.Create))
                    {
                        await fileExcel.CopyToAsync(stream);

                        using (XLWorkbook workBook = new XLWorkbook(stream, XLEventTracking.Disabled))
                        {
                            //перегляд усіх листів (в даному випадку категорій)
                            foreach (IXLWorksheet worksheet in workBook.Worksheets)
                            {
                                //worksheet.Name - назва категорії. Пробуємо знайти в БД, якщо відсутня, то створюємо нову
                                Faculties newfac;
                                var       c = (from fac in _context.Faculties
                                               where fac.FacultyName.Contains(worksheet.Name)
                                               select fac).ToList();
                                if (c.Count > 0)
                                {
                                    newfac = c[0];
                                }
                                else
                                {
                                    newfac             = new Faculties();
                                    newfac.FacultyName = worksheet.Name;
                                    // newgrp.Info = "from EXCEL";
                                    //додати в контекст
                                    _context.Faculties.Add(newfac);
                                }
                                //перегляд усіх рядків
                                foreach (IXLRow row in worksheet.RowsUsed().Skip(1))
                                {
                                    try
                                    {
                                        Cathedras newcath  = null;
                                        bool      flagg    = false;
                                        string    cathName = row.Cell(1).Value.ToString();
                                        var       v        = _context.Cathedras.ToArray();
                                        foreach (Cathedras cath in v)
                                        {
                                            string cath2Name = cath.CathedraName.ToString();
                                            if (cath2Name.Contains(cathName))
                                            {
                                                flagg = true; newcath = cath; break;
                                            }
                                        }

                                        /*   string cathName = row.Cell(1).Value.ToString();
                                         * var v = (from cath in _context.Cathedras  //.Where(k => k.FacultyId == newfac.Id)
                                         *          where cath.CathedraName.Contains(cathName)
                                         *         select cath).ToList();
                                         * if (v.Count>0)
                                         * {
                                         *     newcath = v[0];
                                         * } */
                                        if (!flagg)
                                        {
                                            newcath = new Cathedras();
                                            newcath.CathedraName = row.Cell(1).Value.ToString();
                                            newcath.FacultyId    = newfac.Id;
                                            newcath.Faculty      = newfac;
                                            // newgrp.Info = "from EXCEL";
                                            //додати в контекст
                                            _context.Cathedras.Add(newcath);
                                        }

                                        Group  newgrp;
                                        string grpName = row.Cell(2).Value.ToString();
                                        var    b       = (from grp in _context.Group
                                                          where grp.GroupName.Contains(grpName)
                                                          select grp).ToList();
                                        if (b.Count > 0)
                                        {
                                            newgrp = b[0];
                                        }
                                        else
                                        {
                                            newgrp                = new Group();
                                            newgrp.GroupName      = row.Cell(2).Value.ToString();
                                            newgrp.TypeOfStudying = Convert.ToInt32(row.Cell(3).Value.ToString());
                                            newgrp.CathedraId     = newcath.Id;
                                            newgrp.Cathedra       = newcath;
                                            // newgrp.Info = "from EXCEL";
                                            //додати в контекст
                                            _context.Group.Add(newgrp);
                                        }


                                        Aspirant aspirant = new Aspirant();
                                        aspirant.Name     = row.Cell(4).Value.ToString();
                                        aspirant.Surname  = row.Cell(5).Value.ToString();
                                        aspirant.BirthDay = (DateTime)row.Cell(6).Value;
                                        // book.Info = row.Cell(6).Value.ToString();
                                        aspirant.Group   = newgrp;
                                        aspirant.GroupId = newgrp.Id;
                                        bool flag      = true;
                                        var  aspirants = _context.Aspirant.Where(n => n.GroupId == newgrp.Id).ToArray();
                                        foreach (var asp in aspirants)
                                        {
                                            if ((asp.Name == aspirant.Name) && (asp.Surname == aspirant.Surname) && (asp.BirthDay == aspirant.BirthDay))
                                            {
                                                flag = false; break;
                                            }
                                        }
                                        if (flag)
                                        {
                                            _context.Aspirant.Add(aspirant);
                                            await _context.SaveChangesAsync();
                                        }
                                    }
                                    catch (Exception e)
                                    {
                                        //logging самостійно :)
                                    }
                                }
                            }
                        }
                    }
                }

                await _context.SaveChangesAsync();
            }
            return(RedirectToAction(nameof(Index)));
        }
Esempio n. 13
0
        private static void AspirantInit(AspiranturaContext context)
        {
            var aspirants = new Aspirant[] {
                // new Aspirant { Name = "Олександр", Surename = "Бука", Birthday = DateTime.Parse ("1989-09-01"), Patronymic = "Петрович", StatustypeId = (int) StatusType.новий, SpecialityId = 73, InputDate = DateTime.Parse ("2018-09-01"), StudyformId=(int)FormEnum.Денна },
                // new Aspirant { Name = "Сергій", Surename = "Гітієс", Birthday = DateTime.Parse ("1992-09-01"), Patronymic = "Васильевич", StatustypeId = (int) StatusType.новий, SpecialityId = 75, StudyformId=(int)FormEnum.Денна },
                // new Aspirant { Name = "Кирило", Surename = "Вітус", Birthday = DateTime.Parse ("1991-09-01"), StatustypeId = (int) StatusType.навчання, SpecialityId = 113, StudyformId=(int) FormEnum.Денна },
                // new Aspirant { Name = "Михайло", Surename = "Barzdukas", Birthday = DateTime.Parse ("1992-09-01"), StatustypeId = (int) StatusType.новий, SpecialityId = 113, StudyformId=(int)FormEnum.Денна },
                // new Aspirant { Name = "Yan", Surename = "Li", Birthday = DateTime.Parse ("1985-09-01"), StatustypeId = (int) StatusType.відрахований_2, SpecialityId = 113, StudyformId=(int)FormEnum.Заочна },
                // new Aspirant { Name = "Альберт", Surename = "Justice", Birthday = DateTime.Parse ("1991-09-01"), StatustypeId = (int) StatusType.відрахований_2, SpecialityId = 73, StudyformId=(int)FormEnum.Вечірня },
                // new Aspirant { Name = "Laura", Surename = "Norman", Birthday = DateTime.Parse ("1991-09-01"), StatustypeId = (int) StatusType.захист_достроково, SpecialityId = 73, StudyformId=(int)FormEnum.Денна },
                // new Aspirant { Name = "Nino", Surename = "Olivetto", Birthday = DateTime.Parse ("1990-09-01"), StatustypeId = (int) StatusType.стажування, SpecialityId = 113, StudyformId=(int)FormEnum.Вечірня }

                new Aspirant {
                    Name = "Олександр", Surename = "Бука", Birthday = DateTime.Parse("1989-09-01"), Patronymic = "Петрович", StatusType = StatusType.новий, SpecialityId = 73, InputDate = DateTime.Parse("2018-09-01"), StudyForm = StudyForm.денна
                },
                new Aspirant {
                    Name = "Сергій", Surename = "Гітієс", Birthday = DateTime.Parse("1992-09-01"), Patronymic = "Васильевич", StatusType = StatusType.новий, SpecialityId = 75, StudyForm = StudyForm.вечірня
                },
                new Aspirant {
                    Name = "Кирило", Surename = "Вітус", Birthday = DateTime.Parse("1991-09-01"), StatusType = StatusType.навчання, SpecialityId = 113, StudyForm = StudyForm.денна
                },
                new Aspirant {
                    Name = "Михайло", Surename = "Barzdukas", Birthday = DateTime.Parse("1992-09-01"), StatusType = StatusType.новий, SpecialityId = 113, StudyForm = StudyForm.денна
                },
                new Aspirant {
                    Name = "Yan", Surename = "Li", Birthday = DateTime.Parse("1985-09-01"), StatusType = StatusType.відрахований, SpecialityId = 113, StudyForm = StudyForm.заочна
                },
                new Aspirant {
                    Name = "Альберт", Surename = "Justice", Birthday = DateTime.Parse("1991-09-01"), StatusType = StatusType.захист_достроково, SpecialityId = 73, StudyForm = StudyForm.вечірня
                },
                new Aspirant {
                    Name = "Laura", Surename = "Norman", Birthday = DateTime.Parse("1991-09-01"), StatusType = StatusType.захист_достроково, SpecialityId = 73, StudyForm = StudyForm.денна
                },
                new Aspirant {
                    Name = "Nino", Surename = "Olivetto", Birthday = DateTime.Parse("1990-09-01"), StatusType = StatusType.стажування, SpecialityId = 113, StudyForm = StudyForm.вечірня
                }
            };

            foreach (Aspirant asp in aspirants)
            {
                context.Aspirants.Add(asp);
            }
            context.SaveChanges();

            // var aspirantOrders = new AspirantOrder[]
            // {
            //      new AspirantOrder {
            //          AspirantId = aspirants.Single(a => a.Name == "Carson").Id,
            //          OrderId = 1
            //          },
            //      new AspirantOrder {
            //          AspirantId = aspirants.Single(a => a.Name == "Meredith").Id,
            //          OrderId = 1
            //          }
            //};
            // foreach (AspirantOrder ao in aspirantOrders)
            // {
            //     context.AspirantOrders.Add(ao);
            // }
            // context.SaveChanges();
        }