public static CourseApiModel ToModel(this Course entity)
        {
            var model = new CourseApiModel();

            model.Id             = entity.Id;
            model.Name           = entity.Name;
            model.Description    = entity.Description;
            model.OwnerId        = entity.OwnerId;
            model.Owner          = entity.Owner;
            model.CourseCategory = entity.CourseCategory;
            model.CourseFee      = entity.CourseFee;

            if (string.IsNullOrWhiteSpace(entity.AvailableFrom.ToString()))
            {
                model.AvailableFrom = Constants.DEFAULT_DATEOFBIRTH;
            }
            else
            {
                model.AvailableFrom = entity.AvailableFrom.ToString();
            }

            if (string.IsNullOrWhiteSpace(entity.AvailableTo.ToString()))
            {
                model.AvailableTo = Constants.DEFAULT_DATEOFBIRTH;
            }
            else
            {
                model.AvailableTo = entity.AvailableTo.ToString();
            }

            model.CourseImage = UtilCommon.GetDisplayImageUrl(entity.CourseImage);

            return(model);
        }
        public static UserModel ToUserModel(this User user, UserRole role)
        {
            var model = new UserModel();

            if (user != null)
            {
                model.UserId     = user.Id;
                model.Avatar     = UtilCommon.GetDisplayImageUrl(user.Avatar);
                model.FullName   = user.FullName;
                model.Email      = user.Email;
                model.Phone      = user.Phone;
                model.Role       = user.Role;
                model.Gender     = user.Gender;
                model.LinkedSite = user.LinkedSite;
                model.Address    = user.Address;
                model.Bio        = user.Bio;
                model.Location   = user.Location;
                model.Strength   = user.Strength;
                model.Languages  = user.Languages;
                model.UserName   = user.UserName;
                model.UserId     = user.Id;

                if (string.IsNullOrWhiteSpace(user.DateOfBirth.ToString()))
                {
                    model.DateOfBirth = Constants.DEFAULT_DATEOFBIRTH;
                }
                else
                {
                    model.DateOfBirth = user.DateOfBirth.ToString();
                }
            }

            return(model);
        }
        public async Task <ResponseModel> LoginUser(LoginModel loginModel)
        {
            ResponseModel result = new ResponseModel();

            User user = null;

            if (!string.IsNullOrWhiteSpace(loginModel.Email))
            {
                user = _userRepo.GetUserByEmailAsync(loginModel.Email, true);
            }

            if (user == null)
            {
                result.Error  = ErrorMessageCode.USER_NOT_FOUND;
                result.Status = HttpStatusCode.NotFound;
                return(result);
            }

            if (user.IsDeactivate)
            {
                result.Error  = ErrorMessageCode.USER_IS_DEACTIVATE;
                result.Status = HttpStatusCode.Forbidden;
                return(result);
            }

            try
            {
                var passcode    = UtilCommon.GeneratePasscode(loginModel.PassCode, user.Salt);
                var expireToken = 1;
                if (passcode.Equals(user.PassCode))
                {
                    result.Status = System.Net.HttpStatusCode.OK;
                    LoginApiModel data = new LoginApiModel();
                    data.IsFirstLogin = user.IsFirstLogin;
                    data.Token        = _jwtHandler.Create(user.Id.ToString(), expireToken, user.Role);
                    data.Avatar       = UtilCommon.GetDisplayImageUrl(user.Avatar);
                    data.FullName     = user.FullName;
                    data.Role         = user.Role;
                    data.UserId       = user.Id;
                    result.Data       = data;
                    await _userRepo.UpdateAsync(user);

                    return(result);
                }
                else
                {
                    result.Error  = ErrorMessageCode.PASSWORD_INCORRECT;
                    result.Status = System.Net.HttpStatusCode.NotFound;
                    var date = DateTime.UtcNow;
                    return(result);
                }
            }
            catch (Exception ex)
            {
                result.Error  = ex.ToString();
                result.Status = System.Net.HttpStatusCode.NotImplemented;
                return(result);
            }
        }