Ejemplo n.º 1
0
        public async Task <IActionResult> Post([FromBody] SchoolAdminViewModel model)
        {
            try
            {
                var user = new User
                {
                    FullName    = model.FullName,
                    Email       = model.Email,
                    PhoneNumber = model.PhoneNumber
                };


                ILogger <UsersController> logger       = new LoggerFactory().CreateLogger <UsersController>();
                OkObjectResult            userResponse = (OkObjectResult)await new UsersController(Config, logger, DataContext).Post(user);

                var schoolAdmin = new SchoolAdmin
                {
                    CoursesId  = model.CoursesId,
                    Deleted    = false,
                    GroupsId   = model.GroupsId,
                    TeachersId = model.TeachersId,
                    Type       = model.Type,
                    UserId     = Convert.ToString(userResponse.Value),
                    SchoolId   = model.SchoolId
                };

                await UnitOfWork.Repository <SchoolAdmin>().InsertAsync(schoolAdmin);

                return(new OkObjectResult(schoolAdmin.Id));
            }
            catch (Exception ex)
            {
                return(new BadRequestResult());
            }
        }
Ejemplo n.º 2
0
        public ActionResult DeleteConfirmed(int id)
        {
            SchoolAdmin schooladmin = schoolAdminDbContext.dbSet.Find(id);

            schoolAdminDbContext.dbSet.Remove(schooladmin);
            schoolAdminDbContext.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 3
0
 public ActionResult Edit(SchoolAdmin schoolAdmin)
 {
     if (ModelState.IsValid)
     {
         schoolAdminDbContext.Entry(schoolAdmin).State = EntityState.Modified;
         schoolAdminDbContext.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(schoolAdmin));
 }
Ejemplo n.º 4
0
        public ActionResult Create(SchoolAdmin schooladmin)
        {
            if (ModelState.IsValid)
            {
                schoolAdminDbContext.dbSet.Add(schooladmin);
                schoolAdminDbContext.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(schooladmin));
        }
Ejemplo n.º 5
0
        public ActionResult ViewSchoolAdmin(string deleteIdsList)
        {
            List <int> idsToDelete = (List <int>)js.Deserialize(deleteIdsList, typeof(List <int>));

            foreach (int id in idsToDelete)
            {
                SchoolAdmin admin = schoolAdminDbContext.dbSet.Find(id);
                schoolAdminDbContext.dbSet.Remove(admin);
                schoolAdminDbContext.SaveChanges();
            }
            return(RedirectToAction("Index"));
        }
        public async Task RequestAdminAsync(string userId, string schoolId)
        {
            var existingAdmin = await _repo.SchoolAdmins.FirstOrDefaultAsync(m => m.UserId == userId && m.SchoolId == schoolId);

            if (existingAdmin == null)
            {
                existingAdmin = new SchoolAdmin()
                {
                    UserId = userId, SchoolId = schoolId, AdminStatus = AdminStatus.Pending
                };
                await _repo.SchoolAdmins.AddOrUpdateAndSaveAsync(existingAdmin);
            }
        }
Ejemplo n.º 7
0
 public ActionResult AddSchoolAdmin(string userId, string schoolIdsList, string role)
 {
     if (userId != null)
     {
         int id = int.Parse(userId);
         // create list from string
         List <int> schoolsIdsToAdd = (List <int>)js.Deserialize(schoolIdsList, typeof(List <int>));
         //add the user admin for all the schools.
         foreach (var item in schoolsIdsToAdd)
         {
             //create admin
             SchoolAdmin admin = new SchoolAdmin();
             admin.schoolId = item;
             admin.userId   = id;
             //add admin to database
             schoolAdminDbContext.dbSet.Add(admin);
             schoolAdminDbContext.SaveChanges();
         }
     }
     // If we got this far, something failed, redisplay form
     return(RedirectToAction("Index"));
 }
Ejemplo n.º 8
0
        public async Task <IActionResult> Put(string id, [FromBody] SchoolAdmin schooladmin)
        {
            var document = new BsonDocument
            {
                { "UserId", schooladmin.UserId },
                { "TeachersId", new BsonArray(schooladmin.TeachersId) },
                { "CoursesId", new BsonArray(schooladmin.CoursesId) },
                { "GroupsId", new BsonArray(schooladmin.GroupsId) },
                { "Type", schooladmin.Type },
                { "Deleted", false },
                { "SchoolId", ObjectId.Parse(schooladmin.SchoolId) }
            };

            try
            {
                UnitOfWork.Repository <SchoolAdmin>().UpdateAsync(document, ObjectId.Parse(id), "schooladmins");
                return(new OkObjectResult(schooladmin.Id));
            }
            catch (Exception ex)
            {
                return(new BadRequestResult());
            }
        }
Ejemplo n.º 9
0
 public async Task <IActionResult> DeleteById(string id)
 {
     try
     {
         SchoolAdmin schooladmin = (SchoolAdmin)this.GetById(id).Result;
         var         document    = new BsonDocument
         {
             { "UserId", schooladmin.UserId },
             { "TeachersId", new BsonArray(schooladmin.TeachersId) },
             { "CoursesId", new BsonArray(schooladmin.CoursesId) },
             { "GroupsId", new BsonArray(schooladmin.GroupsId) },
             { "Type", schooladmin.Type },
             { "Deleted", true },
             { "SchoolId", ObjectId.Parse(schooladmin.SchoolId) }
         };
         UnitOfWork.Repository <SchoolAdmin>().DeleteAsync(document, ObjectId.Parse(id), "schooladmins", true);
         return(new OkObjectResult(schooladmin));
     }
     catch (Exception ex)
     {
         return(new BadRequestResult());
     }
 }
        public bool Put(SchoolAdmin admin)
        {
            SchoolAdminRepository adminRepository = new SchoolAdminRepository();

            return(adminRepository.Put(admin));
        }
Ejemplo n.º 11
0
        private async Task SeedSchoolUsers()
        {
            _logger.LogDebug("Start Seeding Student...");
            if (_ctx.Students.FirstOrDefault() == null)
            {
                var student = new Student
                {
                    FirstName  = "Sladi",
                    SecondName = "Sladkov",
                    LastName   = "Sladkov",
                    Pin        = "0510043827",
                    Address    = "Някъде от София",
                    Town       = "София",
                    StartYear  = 2018,
                    School     = _ctx.Schools.FirstOrDefault(),
                    Class      = _ctx.Classes.FirstOrDefault()
                };
                var account = await CreateAspUser(student, RoleTypes.Student);

                if (account != null)
                {
                    student.User = account;
                    student.Id   = account.Id;
                    _ctx.Students.Add(student);
                    await _ctx.SaveChangesAsync();
                }
            }

            _logger.LogDebug("Student Seeded");


            _logger.LogDebug("Start Seeding Teacher...");
            if (_ctx.Teachers.FirstOrDefault() == null)
            {
                var teacher = new Teacher
                {
                    FirstName  = "Dimitar",
                    SecondName = "Gospodinov",
                    LastName   = "Prepodavatelov",
                    Pin        = "124304932",
                    Address    = "Shishman 52",
                    Town       = "Sofia",
                    School     = _ctx.Schools.FirstOrDefault()
                };


                var account = await CreateAspUser(teacher, RoleTypes.Teacher);

                var someClass = _ctx.Classes.FirstOrDefault();

                if (someClass != null && account != null)
                {
                    someClass.ClassTeacher = teacher;
                    teacher.User           = account;
                    teacher.Id             = account.Id;
                    _ctx.Teachers.Add(teacher);
                }
            }

            _logger.LogDebug("Teacher Seeded");

            _logger.LogDebug("Start Seeding Parent...");
            if (_ctx.Parents.FirstOrDefault() == null)
            {
                var parent = new Parent
                {
                    FirstName  = "Bashatata",
                    SecondName = "Na",
                    LastName   = "Sladi",
                    Pin        = "412412e2d324",
                    Address    = "Някъде от София",
                    Town       = "София",
                    School     = _ctx.Schools.FirstOrDefault()
                };

                var student = _ctx.Students.FirstOrDefault();
                var account = await CreateAspUser(parent, RoleTypes.Parent);

                if (parent.Children != null && account != null)
                {
                    parent.User = account;
                    parent.Children.Add(student);
                    _logger.LogInformation(parent.ToString());
                    _ctx.Parents.Add(parent);
                }
            }

            _logger.LogDebug("Parent Seeded");

            _logger.LogDebug("Start Seeding Principal...");
            if (_ctx.Principals.FirstOrDefault() == null)
            {
                var principal = new Principal
                {
                    FirstName  = "Principal",
                    SecondName = "Of",
                    LastName   = "School",
                    Pin        = "1243049888",
                    Address    = "Street 52",
                    Town       = "Sofia",
                    School     = _ctx.Schools.FirstOrDefault()
                };


                var account = await CreateAspUser(principal, RoleTypes.Principal);

                if (account != null)
                {
                    principal.User = account;
                    principal.Id   = account.Id;
                    _ctx.Principals.Add(principal);
                }
            }

            _logger.LogDebug("Principal Seeded");

            _logger.LogDebug("Start Seeding School Admin...");
            if (_ctx.SchoolUsers.FirstOrDefault(x =>
                                                x.Role == RoleTypes.SchoolAdmin) == null)
            {
                var schoolAdmin = new SchoolAdmin
                {
                    FirstName  = "School",
                    SecondName = "Admin",
                    LastName   = "Test",
                    Pin        = "1243049999",
                    Address    = "45 Admin str.",
                    Town       = "Sofia",
                    School     = _ctx.Schools.FirstOrDefault()
                };


                var account = await CreateAspUser(schoolAdmin, RoleTypes.SchoolAdmin);

                if (account != null)
                {
                    schoolAdmin.User = account;
                    schoolAdmin.Id   = account.Id;
                    _ctx.SchoolUsers.Add(schoolAdmin);
                }
            }

            _logger.LogDebug("School Admin Seeded");

            _ctx.SaveChanges();
        }
Ejemplo n.º 12
0
        //
        // GET: /SchoolAdmins/Delete/5

        public ActionResult Delete(int id)
        {
            SchoolAdmin schoolAdmin = schoolAdminDbContext.dbSet.Find(id);

            return(View(schoolAdmin));
        }
Ejemplo n.º 13
0
        //
        // GET: /SchoolAdmins/Details/5

        public ViewResult Details(int id)
        {
            SchoolAdmin schooladmin = schoolAdminDbContext.dbSet.Find(id);

            return(View(schooladmin));
        }