Exemple #1
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(StPrograms).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CustomersExists(StPrograms.Id.ToString()))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
Exemple #2
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.StPrograms.Add(StPrograms);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
        public async Task <IActionResult> OnPostAsync(string id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Supervisors = await _context.Supervisors.FindAsync(Int32.Parse(id));

            Themes = await _context.Themes.Where(t => t.SupervisorId == Int32.Parse(id)).ToListAsync();

            if (Supervisors != null)
            {
                _context.Supervisors.Remove(Supervisors);
                _context.Themes.RemoveRange(Themes);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
        public async Task <IActionResult> OnPostAsync(string id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Themes = await _context.Themes.FindAsync(Int32.Parse(id));

            Supervisor = await _context.Supervisors.FirstOrDefaultAsync(m => m.Id == Themes.SupervisorId);

            StProgram = await _context.StPrograms.FirstOrDefaultAsync(m => m.Id == Themes.StProgramId);

            if (Themes != null)
            {
                _context.Themes.Remove(Themes);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
        public async Task <IActionResult> OnPostUploadFile(IFormFile fileName)
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            #region ClearDbCommands

            _context.Database.ExecuteSqlCommand("DELETE FROM Theme");
            await _context.SaveChangesAsync();

            _context.Database.ExecuteSqlCommand("DELETE FROM Supervisor");
            await _context.SaveChangesAsync();

            _context.Database.ExecuteSqlCommand("DELETE FROM StProgram");
            await _context.SaveChangesAsync();

            #endregion

            StreamReader reader = new StreamReader(fileName.OpenReadStream());
            reader.ReadLine();
            while (!reader.EndOfStream)
            {
                var line = reader.ReadLine();
                if (!string.IsNullOrWhiteSpace(line))
                {
                    var values = line.Split(';');

                    if (_context.Supervisors.Count(s => s.FullName == values[1]) == 0)
                    {
                        var inserting = new Supervisor();
                        inserting.FullName = values[1];
                        _context.Supervisors.Add(inserting);
                        await _context.SaveChangesAsync();
                    }
                    if (_context.StPrograms.Where(s => s.Name == values[2]).Count(s => s.FieldOfStudy == values[3]) == 0)
                    {
                        var inserting = new StProgram();
                        inserting.Name         = values[2];
                        inserting.FieldOfStudy = values[3];
                        _context.StPrograms.Add(inserting);
                        await _context.SaveChangesAsync();
                    }
                    if (_context.Themes.Where(t => t.Name == values[0])
                        .Where(t => t.StProgramId == _context.StPrograms.FirstOrDefault(s => s.Name == values[2]).Id)
                        .Count(t => t.StProgramId == _context.StPrograms.FirstOrDefault(s => s.FieldOfStudy == values[3]).Id) == 0)
                    {
                        var inserting = new Theme();
                        inserting.Name = values[0];
                        var sup = _context.Supervisors.First(s => s.FullName == values[1]);
                        inserting.SupervisorId = sup.Id;
                        inserting.Supervisor   = sup;
                        var stu = _context.StPrograms
                                  .Where(s => s.Name == values[2]).First(s => s.FieldOfStudy == values[3]);
                        inserting.StProgramId     = stu.Id;
                        inserting.StProgram       = stu;
                        inserting.IsFullTimeStudy = Boolean.Parse(values[4]);
                        inserting.IsExternalStudy = Boolean.Parse(values[5]);
                        ResearchType?resType = null;
                        switch (values[6].ToLower())
                        {
                        case "základný výskum":
                            resType = ResearchType.BasicResearch;
                            break;

                        case "aplikovaný výskum":
                            resType = ResearchType.AppliedResearch;
                            break;

                        case "aplikovaný výskum a experimentálny vývoj":
                            resType = ResearchType.AppliedResearchExpDevelopment;
                            break;

                        case null:
                            break;

                        default:
                            throw new ArgumentOutOfRangeException();
                        }
                        inserting.ResearchType = resType;
                        string desc = values[7];
                        desc = desc.Replace("<br>", Environment.NewLine);
                        inserting.Description = desc;
                        inserting.Created     = DateTime.Parse(values[8]);
                        _context.Themes.Add(inserting);
                        await _context.SaveChangesAsync();
                    }
                }
            }
            reader.Close();

            return(RedirectToPage("./Index"));
        }