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 <long> MapStaffUser(long userId, long staffId)
        {
            var nStaffMap = new StaffUserMap
            {
                UserId     = userId,
                StaffId    = staffId,
                DateMapped = DateTime.UtcNow
            };
            await _schoolHubDbContext.StaffUserMap.AddAsync(nStaffMap);

            await _schoolHubDbContext.SaveChangesAsync();

            return(nStaffMap.Id);
        }
Exemplo n.º 4
0
        public async Task <PaymentResponse> MakePayment(PaymentRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            using (var _transaction = _schoolhubDbContext.Database.BeginTransaction())
            {
                var nFeeType = (int)request.FeeType;
                var payment  = new Payment
                {
                    StudentId         = request.StudentId,
                    ClassId           = request.ClassId,
                    FeeType           = request.FeeType,
                    PaymentDate       = DateTime.UtcNow,
                    PaymentRefernceId = $"SchoolHub-{Guid.NewGuid().ToString().Substring(5)}",
                    PaymentStatus     = PaymentStatus.Paid,
                    Amount            = RetrieveAmountByClassIdAndFeeType(request.ClassId, nFeeType).Result
                };

                await _schoolhubDbContext.Payment.AddAsync(payment);

                await _schoolhubDbContext.SaveChangesAsync();

                var response = new PaymentResponse
                {
                    PayChannel = new PayChannel
                    {
                        ClassId   = payment.ClassId,
                        StudentId = payment.StudentId
                    },
                    PaymentReport = new PaymentReport
                    {
                        PaymentRefrenceId = payment.PaymentRefernceId,
                        FeeType           = payment.FeeType.GetDescription(),
                        PaymentStatus     = payment.PaymentStatus.GetDescription(),
                        Amount            = payment.Amount,
                    }
                };
                _transaction.Commit();

                return(response);
            }
        }
Exemplo n.º 5
0
        public async Task <long> InsertUser(CreateUserDto model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            using (var txn = _schoolHubDbContext.Database.BeginTransaction())
            {
                CreatePasswordEncrypt(model.Password, out byte[] passwordHash, out byte[] passwordSalt);

                var newUser = new User
                {
                    Username         = model.Username,
                    Password         = model.Password,
                    EmailAddress     = model.EmailAddress,
                    PasswordHash     = passwordHash,
                    PasswordSalt     = passwordSalt,
                    IsEmailConfirmed = false,
                    IsUpdated        = false,
                    IsAdmin          = false,
                    UserType         = (int)model.UserType,
                };
                if (model.UserType == UserTypeEnum.Admin)
                {
                    newUser.IsAdmin = true;
                }
                await _schoolHubDbContext.User.AddAsync(newUser);

                await _schoolHubDbContext.SaveChangesAsync();

                //TODO: Send Email to User
                #region New Registration Notification
                const int type = (int)NotificationType.Registration;
                await _notificationProcess.ProcessNotificationAsync(newUser, type);

                #endregion
                txn.Commit();
                return(await Task.FromResult(newUser.Id));
            }
        }
Exemplo n.º 6
0
        public async Task <long> InsertSubject(CreateSubjectDto model)
        {
            Subject subject;

            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }
            subject = new Subject
            {
                SubjectCode = model.SubjectCode,
                SubjectName = model.SubjectName,
                CreatedOn   = DateTime.UtcNow,
                CreatedBy   = model.CreatedBy
            };
            await _schoolHubDbContext.Subject.AddAsync(subject);

            await _schoolHubDbContext.SaveChangesAsync();

            return(subject.Id);
        }
Exemplo n.º 7
0
        public async Task <long> InsertClass(CreateClassDto model)
        {
            ClassName className;

            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }
            className = new ClassName
            {
                ClassCode = model.ClassCode,
                Name      = model.Name,
                Category  = model.Category,
                CreatedOn = DateTime.UtcNow,
            };
            await _schoolHubDbContext.ClassName.AddAsync(className);

            await _schoolHubDbContext.SaveChangesAsync();

            return(className.Id);
        }
Exemplo n.º 8
0
        public async Task <long> InsertStudent(long classId, CreateStudentDto model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }
            if (classId < 1)
            {
                throw new ArgumentNullException(nameof(classId));
            }

            var student = new Student
            {
                Firstname          = model.Firstname,
                Middlename         = model.Middlename,
                Lastname           = model.Lastname,
                DateOfBirth        = model.DateOfBirth,
                DateOfRegistration = model.DateOfRegistration,
                Gender             = model.Gender.GetDescription(),
            };
            await _schoolHubDbContext.Student.AddAsync(student);

            await _schoolHubDbContext.SaveChangesAsync();

            var classMapp = await _classAppService.RetrieveClassById(classId);

            var studentClassMap = new StudentClassMap
            {
                ClassId   = classMapp.Id,
                StudentId = student.Id,
            };

            await _schoolHubDbContext.StudentClassMap.AddAsync(studentClassMap);

            await _schoolHubDbContext.SaveChangesAsync();

            return(student.Id);
        }