Exemplo n.º 1
0
        public async Task <AuthResponse> ChangePassword(string email, string oldPassword, string newPassword)
        {
            var checkUser = await _schoolHubDbContext.User.FirstOrDefaultAsync(u => u.EmailAddress == email && u.Password == oldPassword && u.IsEmailConfirmed == false);

            CreatePasswordEncrypt(newPassword, out byte[] passwordHash, out byte[] passwordSalt);

            if (checkUser != null)
            {
                checkUser.Password         = newPassword;
                checkUser.PasswordHash     = passwordHash;
                checkUser.PasswordSalt     = passwordSalt;
                checkUser.IsEmailConfirmed = true;
            }
            _schoolHubDbContext.Entry(checkUser).State = EntityState.Modified;
            await _schoolHubDbContext.SaveChangesAsync();

            var response = new AuthResponse
            {
                Status  = true,
                Success = AuthResponseEnum.Yes.GetDescription()
            };

            //TODO: Send Email to User
            #region New Password Change Notification
            const int type = (int)NotificationType.PasswordChange;
            await _notificationProcessor.ProcessNotificationAsync(checkUser, type);

            #endregion
            return(response);
        }
Exemplo n.º 2
0
        public async Task <long> InsertStaff(CreateStaffDto model)
        {
            Staff staff;

            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }
            var user = await _userAppService.RetrieveUser(model.UserId);

            var checkStaff = await RetriveStaffByUserId(model.UserId);

            if (checkStaff != null)
            {
                return(0);
            }
            else
            {
                staff = new Staff
                {
                    UserId       = user.Id,
                    Firstname    = model.Firstname,
                    Middlename   = model.Middlename,
                    Lastname     = model.Lastname,
                    DateOfBirth  = model.DateOfBirth,
                    DateEmployed = model.DateEmployed,
                    Gender       = model.Gender,
                    UserType     = user.UserType,
                    IsUpdate     = true,
                    IsActive     = true,
                };
                await _schoolHubDbContext.Staff.AddAsync(staff);

                await _schoolHubDbContext.SaveChangesAsync();

                var nUser = await _schoolHubDbContext.User.Where(s => s.Id == user.Id).FirstOrDefaultAsync();

                if (nUser != null)
                {
                    nUser.IsUpdated = true;
                }
                ;
                _schoolHubDbContext.Entry(nUser).State = EntityState.Modified;
                await _schoolHubDbContext.SaveChangesAsync();
            }

            //INsert into UserStaffMap
            await _mappingService.MapStaffUser(staff.UserId, staff.Id);

            return(await Task.FromResult(staff.Id));
        }
Exemplo n.º 3
0
        public async Task SavePicture(StudentDto studentDto)
        {
            var student = await _schoolHubDbContext.Student.FirstOrDefaultAsync(x => x.Id == studentDto.Id);

            if (student != null)
            {
                student.Id        = studentDto.Id;
                student.ImagePath = studentDto.ImagePath;
            }
            _schoolHubDbContext.Entry(student).State = EntityState.Modified;
            await _schoolHubDbContext.SaveChangesAsync();
        }
Exemplo n.º 4
0
        public async Task <bool> UpdateUser(UpdateUserDto model)
        {
            var user = await _schoolHubDbContext.User.FindAsync(model.Id);

            if (user != null)
            {
                user.Username     = model.Username;
                user.EmailAddress = model.EmailAddress;
                user.UserType     = model.UserType;
                user.UpdatedOn    = DateTime.UtcNow;
                user.Password     = model.Password;
                user.IsUpdated    = true;
            }
            _schoolHubDbContext.Entry(user).State = EntityState.Modified;
            await _schoolHubDbContext.SaveChangesAsync();

            return(await Task.FromResult(true));
        }
Exemplo n.º 5
0
        public async Task <bool> UpdateAmount(AmountDto amountDto)
        {
            if (amountDto == null)
            {
                throw new ArgumentNullException(nameof(amountDto));
            }

            var amountUpdate = await _schoolhubDbContext.Amount.FirstOrDefaultAsync(s => s.Id == amountDto.Id);

            if (amountUpdate != null)
            {
                amountUpdate.Id          = amountDto.Id;
                amountUpdate.FeeAmount   = amountDto.FeeAmount;
                amountUpdate.UpdatedDate = DateTime.UtcNow;

                _schoolhubDbContext.Entry(amountUpdate).State = EntityState.Modified;
                await _schoolhubDbContext.SaveChangesAsync();

                return(true);
            }
            return(false);
        }