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 async Task <IHttpActionResult> School(SchoolAdminViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            await _schoolAdminBuilder.UpdateAsync(model);

            return(Ok());
        }
Ejemplo n.º 3
0
        public async Task <bool> Post(SchoolAdminViewModel schoolAdmin)
        {
            try {
                var client  = new RestClient();
                var request = new RestRequest(url, Method.POST);
                request.RequestFormat = DataFormat.Json;
                request.AddHeader("Content-Type", "application/json");
                request.AddJsonBody(schoolAdmin);
                var restResponse = await client.ExecuteTaskAsync(request, CancellationToken.None);

                return(restResponse.IsSuccessful);
            } catch (Exception e) {
                return(false);
            }
        }
Ejemplo n.º 4
0
        public async Task UpdateAsync(SchoolAdminViewModel model)
        {
            var record = MapUpdate().CreateMapper().Map <SchoolAdmin>(model);

            if (!_repo.RoleManager.RoleExists("SchoolAdmin"))
            {
                var role = new ApplicationRole();
                role.DateCreatedUtc = DateTime.UtcNow;
                role.Name           = "SchoolAdmin";
                await _repo.RoleManager.CreateAsync(role);
            }
            if ((model.AdminStatus == AdminStatus.Approved) && (await _repo.UserManager.IsInRoleAsync(model.UserId, "SchoolAdmin") == false))
            {
                await _repo.UserManager.AddToRoleAsync(model.UserId, "SchoolAdmin");
            }
            if ((model.AdminStatus == AdminStatus.Denied || model.AdminStatus == AdminStatus.Pending) && (await _repo.UserManager.IsInRoleAsync(model.UserId, "SchoolAdmin")))
            {
                await _repo.UserManager.RemoveFromRoleAsync(model.UserId, "SchoolAdmin");
            }
            await _repo.SchoolAdmins.AddOrUpdateAndSaveAsync(record);
        }