Beispiel #1
0
        public async Task <AdminDTOOutUp> RegisterAdminUser(AdminDTOInRegister userModel)
        {
            logger.Info($"Converting admin {userModel.UserName} to model, user service, register admin");
            Admin user = new Admin
            {
                UserName  = userModel.UserName,
                FirstName = userModel.FirstName,
                LastName  = userModel.LastName,
                Email     = userModel.Email
            };

            logger.Info($"sending model to auth repository, register admin {userModel.UserName}");
            var result = await db.AuthRepository.RegisterAdminUser(user, userModel.Password);

            if (!result.Succeeded)
            {
                logger.Info($"Result not succeeded, register admin {userModel.UserName}");
                return(null);
            }

            logger.Info($"Searching for registered admin {userModel.UserName}");
            var userCreated = await db.AuthRepository.FindUser(userModel.UserName, userModel.Password);

            logger.Info($"Converting admin {userModel.UserName} to DTO with simple dto converter");
            AdminDTOOutUp admin = Utilities.ConverterDTO.SimpleDTOConverter <AdminDTOOutUp>(userCreated);

            return(admin);
        }
Beispiel #2
0
        public IHttpActionResult DeleteAdmin(string id)
        {
            string userId = ((ClaimsPrincipal)RequestContext.Principal).FindFirst(x => x.Type == "UserId").Value;

            logger.Info($"Admin {userId} deletes admin");
            AdminDTOOutUp adminDeleted = adminsService.DeleteAdmin(id);

            return(Ok(adminDeleted));
        }
Beispiel #3
0
        public AdminDTOOutUp DeleteAdmin(string id)
        {
            logger.Info("Getting admin by ID, admin service, delete admin");
            AdminDTOOutUp admin = GetAdminById(id);

            logger.Info("Sending admin to admin repo for delete");
            db.AdminsRepository.Delete(id);
            logger.Info("saving delete to db");
            db.Save();
            logger.Info("returning deleted admin. delete admin");
            return(admin);
        }
Beispiel #4
0
        public AdminDTOOutUp GetAdminByUserName(string username)
        {
            logger.Info("Accessing db over admin repo, get admin by username");
            Admin admin = db.AdminsRepository.Get(filter: x => x.UserName == username).FirstOrDefault();

            if (admin == null)
            {
                throw new DepartmentNotFoundException($"Requested admin with username {username} does not exists");
            }
            logger.Info("converting with simpleDTOConverter, get admin by username");
            AdminDTOOutUp adminDTOOut = Utilities.ConverterDTO.SimpleDTOConverter <AdminDTOOutUp>(admin);

            return(adminDTOOut);
        }
Beispiel #5
0
        public AdminDTOOutUp GetAdminById(string id)
        {
            logger.Info("Accssesing db over Admin rep, get admin by id");
            Admin admin = db.AdminsRepository.Get(filter: x => x.Id == id).FirstOrDefault();

            if (admin == null)
            {
                throw new DepartmentNotFoundException("Requested admin doesn't exists");
            }
            logger.Info("converting admin with SimpleDTOConverter, get admin by id");
            AdminDTOOutUp adminDTOOut = Utilities.ConverterDTO.SimpleDTOConverter <AdminDTOOutUp>(admin);

            return(adminDTOOut);
        }
Beispiel #6
0
        public async Task <AdminDTOOutUp> UpdateAdmin(string id, AdminDTOInUp adminInUp)
        {
            logger.Info($"Converting admin {adminInUp.UserName} with simple dto converter, user service update admin");
            Admin admin = Utilities.ConverterDTO.SimpleDTOConverter <Admin>(adminInUp);

            logger.Info($"getting user with id {adminInUp.Id}, with db.authreposito, update admin, user service ");
            AppUser user = await db.AuthRepository.FindUserById(id);

            if (user == null)
            {
                logger.Info("Throwing an user not found exception, no user found update admin, user service");
                throw new UserNotFoundException($"User with ID {id} does not exists.");
            }

            logger.Info($"Updating user {adminInUp.UserName}");
            user.FirstName = adminInUp.FirstName;
            user.LastName  = adminInUp.LastName;
            user.Email     = adminInUp.Email;
            user.UserName  = adminInUp.UserName;

            logger.Info("waiting for result from auth repository, update user, user service");
            var result = await db.AuthRepository.UpdateUser(user);

            if (!result.Succeeded)
            {
                logger.Info("Update has failed, result not succeeded, user service");
                return(null);
            }

            logger.Info("Getting updated user with auth repository");
            var userUpdated = await db.AuthRepository.FindUserById(adminInUp.Id);

            logger.Info("Converting user to teacher dto");
            AdminDTOOutUp adminDTO = Utilities.ConverterDTO.SimpleDTOConverter <AdminDTOOutUp>(userUpdated);

            return(adminDTO);
        }