示例#1
0
        public async Task <IActionResult> Edit(EditInstitutionViewModel model)
        {
            if (ModelState.IsValid)
            {
                var manager = await UserManager.FindByIdAsync(model.ManagerId);

                string name = model.Name;



                var inst = (from i in DBContext.Institutions.Include(m => m.Manager)
                            where i.Id.ToString() == model.Idinst
                            select i).FirstOrDefaultAsync().Result;

                DBContext.Update(inst).Entity.Manager = manager;
                DBContext.Update(inst).Entity.Name    = name;

                await DBContext.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            else
            {
                model.AvailableManagers = await UserManager.GetUsersInRoleAsync("Manager");
            }
            return(View(model));
        }
示例#2
0
        public async Task <IActionResult> Edit(EditDepartmentViewModel model)
        {
            if (ModelState.IsValid)
            {
                var teacher = await UserManager.FindByIdAsync(model.HeadTeacherId);

                string name = model.Name;



                var dep = await(from d in DBContext.Departments.Include(h => h.HeadTeacher)
                                where d.Id.ToString() == model.DepartmentId
                                select d).FirstOrDefaultAsync();

                DBContext.Update(dep).Entity.HeadTeacher = teacher;
                DBContext.Update(dep).Entity.Name        = name;

                await DBContext.SaveChangesAsync();

                return(RedirectToAction("Index", new { InstId = model.InstitutionId }));
            }
            model.AvailableTeachers = await UserManager.GetUsersInRoleAsync("Teacher");

            return(View(model));
        }
示例#3
0
 public async Task <IActionResult> UploadFile(IFormFile upload, string tag, string id, string user)
 {
     //здесь пока что нет вообще никакой безопасности
     if (upload != null)
     {
         if (upload.Length >= 10485760)
         {
             return(RedirectToAction("Index", new { DiscId = id, FileError = true }));
         }
         var    euser   = await(from u in DBContext.Users where u.Email.ToLower() == user.ToLower() select u).FirstOrDefaultAsync();
         string t       = tag;
         string outpath = Environment.WebRootPath + "/DisciplineFiles/" + "id" + id + "/" + tag + "/";
         if (!Directory.Exists(outpath))
         {
             Directory.CreateDirectory(outpath);
         }
         outpath += upload.FileName;
         using (var fileStream = new FileStream(outpath, FileMode.Create))
         {
             await upload.CopyToAsync(fileStream);
         }
         var efile = new EFile()
         {
             DateLoad = DateTime.Today.ToShortDateString(),
             UserLoad = euser,
             Tag      = tag,
             Path     = outpath,
             Name     = upload.FileName
         };
         var disc = await(from di in DBContext.Disciplines.Include(f => f.Files)
                          where di.Id.ToString() == id
                          select di).FirstOrDefaultAsync();
         DBContext.Update(disc).Entity.Files.Add(efile);
         await DBContext.SaveChangesAsync();
     }
     return(RedirectToAction("Index", new { DiscId = id }));
 }
示例#4
0
        public async Task <IActionResult> Edit(EditSpecialityViewModel model)
        {
            if (ModelState.IsValid)
            {
                var spec = await(from s in DBContext.Specialities where s.Id.ToString() == model.SpecId select s).FirstOrDefaultAsync();
                var name = model.Name;

                DBContext.Update(spec).Entity.Name = name;
                await DBContext.SaveChangesAsync();

                return(RedirectToAction("Index", new { DepId = model.DepId }));
            }

            return(View(model));
        }
示例#5
0
        public async Task <IActionResult> Edit(EditDisciplineViewModel model)
        {
            if (ModelState.IsValid)
            {
                var teacher = await userManager.FindByIdAsync(model.TeacherId);

                string name = model.Name;
                var    info = "";
                if (!String.IsNullOrWhiteSpace(model.Info))
                {
                    info = model.Info;
                }

                var disc = await(from d in DBContext.Disciplines.Include(h => h.Teacher)
                                 where d.Id.ToString() == model.DisciplineId
                                 select d).FirstOrDefaultAsync();

                DBContext.Update(disc).Entity.Teacher   = teacher;
                DBContext.Update(disc).Entity.Name      = name;
                DBContext.Update(disc).Entity.ExamType  = model.ExamType;
                DBContext.Update(disc).Entity.LectionH  = model.LectionH;
                DBContext.Update(disc).Entity.PracticeH = model.PracticeH;
                DBContext.Update(disc).Entity.About     = info;
                await DBContext.SaveChangesAsync();

                return(RedirectToAction("Index", new { SpecId = model.SpecialityId }));
            }
            model.AvailableTeachers = await userManager.GetUsersInRoleAsync("Teacher");

            return(View(model));
        }