Exemple #1
0
        public ResponseModel EmployeeLoginAsync(EmployeeLoginDto requestParam)
        {
            ResponseModel res       = new ResponseModel();
            var           userStore = new UserStore <ApplicationUser>(_db);
            var           manager   = new UserManager <ApplicationUser>(userStore);

            var result       = manager.Find(requestParam.Email, requestParam.Password);
            var employeeData = _db2.Employees.FirstOrDefault(o => o.EmployeeId == result.Id);
            var uploadInfo   = _db2.Uploads.Where(o => o.UploadId == result.Id).ToList();


            //check if user login successfully
            if (result == null)
            {
                return(res);
            }
            var roleId = _db3.AspNetUserRoles.FirstOrDefault(o => o.UserId == result.Id);
            var role   = _db2.AspNetRoles.FirstOrDefault(o => o.Id == roleId.RoleId);

            IList <UploadDto> uploadDtos = new List <UploadDto>();

            foreach (var item in uploadInfo)
            {
                var uploadId = new UploadDto()
                {
                    UploadId = item.UploadId
                };
                uploadDtos.Add(uploadId);
            }

            //check if account is activated
            if (result.AccountStatus == StatusType.Pending)
            {
                res.Data = "pending";
                return(res);
            }

            var user = new EmployeeLoginDto()
            {
                Address       = result.Address,
                DateOfBirth   = result.DateOfBirth,
                Email         = result.Email,
                FirstName     = result.FirstName,
                LastName      = result.LastName,
                MiddleName    = result.MiddleName,
                Password      = requestParam.Password,
                PhoneNumber   = result.PhoneNumber,
                PlaceOfBirth  = result.PlaceOfBirth,
                StateOfOrigin = result.StateOfOrigin,
            };

            user.Upload = uploadDtos;
            if (employeeData != null)
            {
                user.BVN  = employeeData.BVN;
                user.NIMC = employeeData.NIMC;
            }
            if (result.Sex == SexType.Male)
            {
                user.Sex = "Male";
            }
            else
            {
                user.Sex = "Female";
            }

            res.Data = user;
            return(res);
        }
Exemple #2
0
        public ResponseModel GetEmployerDetails(ApplicationUser result, EmployeeLoginDto requestParam)
        {
            ResponseModel res = new ResponseModel();

            var employeeData = _db2.Employers.FirstOrDefault(o => o.EmployerId == result.Id);
            var uploadInfo   = _db2.Uploads.Where(o => o.UploadId == result.Id).ToList();

            var roleId = _db3.AspNetUserRoles.FirstOrDefault(o => o.UserId == result.Id);
            var role   = _db2.AspNetRoles.FirstOrDefault(o => o.Id == roleId.RoleId);

            IList <UploadDto> uploadDtos = new List <UploadDto>();

            foreach (var item in uploadInfo)
            {
                var uploadId = new UploadDto()
                {
                    UploadId = item.UploadId
                };
                uploadDtos.Add(uploadId);
            }

            //check if account is activated
            if (result.AccountStatus == StatusType.Pending)
            {
                res.Data = "pending";
                return(res);
            }

            var user = new EmployeeLoginDto()
            {
                Address              = result.Address,
                DateOfBirth          = result.DateOfBirth,
                Email                = result.Email,
                FirstName            = result.FirstName,
                LastName             = result.LastName,
                MiddleName           = result.MiddleName,
                Password             = requestParam.Password,
                PhoneNumber          = result.PhoneNumber,
                PlaceOfBirth         = result.PlaceOfBirth,
                StateOfOrigin        = result.StateOfOrigin,
                NextOfKin            = employeeData.NextOfKin,
                NextOfKinAddress     = employeeData.NextOfKinAddress,
                NextOfKinPhoneNumber = employeeData.NextOfKinPhoneNumber,
                PlaceOfWork          = employeeData.PlaceOfWork,
                Profession           = employeeData.Profession,
                Role = role.Name,
                Id   = employeeData.EmployerId
            };

            user.Upload = uploadDtos;
            if (result.Sex == SexType.Male)
            {
                user.Sex = "Male";
            }
            else
            {
                user.Sex = "Female";
            }

            res.Data = user;
            return(res);
        }